-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
100 lines (76 loc) · 3.18 KB
/
Solution.java
File metadata and controls
100 lines (76 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//They kept saying, "Hail, King of the Jews!" and they kept slapping him. (John 19:3)
package com.javarush.task.task20.task2011;
/*
Externalizable для апартаментов
*/
import java.io.*;
public class Solution {
public static class Apartment implements Externalizable {
private String address;
private int year;
/**
* Mandatory public no-arg constructor.
*/
public Apartment() { super(); }
public Apartment(String adr, int y) {
address = adr;
year = y;
}
/**
* Prints out the fields. used for testing!
*/
public String toString() {
return("Address: " + address + "\n" + "Year: " + year);
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(this.address);
out.writeInt(this.year);
out.close();
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
this.address = (String)in.readObject();
this.year = in.readInt();
in.close();
}
}
public static void main(String[] args) {
}
}
/*
Externalizable для апартаментов
Реализуй интерфейс Externalizable в классе Apartment.
Требования:
1. Класс Solution.Apartment должен поддерживать интерфейс Externalizable.
2. В классе Solution.Apartment должен быть реализован метод writeExternal с одним параметром типа ObjectOutput.
3. В классе Solution.Apartment должен быть реализован метод readExternal с одним параметром типа ObjectInput.
4. В методе writeExternal, на полученном в качестве параметра объекте типа ObjectOutput должен быть вызван метод writeObject с параметром address.
5. В методе writeExternal, на полученном в качестве параметра объекте типа ObjectOutput должен быть вызван метод writeInt с параметром year.
6. Метод readExternal должен корректно восстанавливать из ObjectInput значение поля address.
7. Метод readExternal должен корректно восстанавливать из ObjectInput значение поля year.
package com.javarush.task.task20.task2011;
*
Externalizable для апартаментов
*
public class Solution {
public static class Apartment {
private String address;
private int year;
/**
* Mandatory public no-arg constructor.
*/
public Apartment() { super(); }
public Apartment(String adr, int y) {
address = adr;
year = y;
}
/**
* Prints out the fields. used for testing!
*/
public String toString() {
return("Address: " + address + "\n" + "Year: " + year);
}
}
public static void main(String[] args) {
}
}
*/