-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
92 lines (74 loc) · 3.44 KB
/
Solution.java
File metadata and controls
92 lines (74 loc) · 3.44 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
//When therefore the chief priests and the officers saw him, they shouted, saying, "Crucify! Crucify!" Pilate said to them, "Take him yourselves, and crucify him, for I find no basis for a charge against him." (John 19:6)
package com.javarush.task.task20.task2014;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.*;
/*
Serializable Solution
*/
public class Solution implements Serializable {
public static void main(String[] args) {
System.out.println(new Solution(4));
}
private final transient String pattern = "dd MMMM yyyy, EEEE";
private transient Date currentDate;
private transient int temperature;
String string;
public Solution(int temperature) {
this.currentDate = new Date();
this.temperature = temperature;
string = "Today is %s, and current temperature is %s C";
SimpleDateFormat format = new SimpleDateFormat(pattern);
this.string = String.format(string, format.format(currentDate), temperature);
}
@Override
public String toString() {
return this.string;
}
}
/*
Serializable Solution
Сериализуй класс Solution.
Подумай, какие поля не нужно сериализовать, пометь ненужные поля модификатором transient.
Объект всегда должен содержать актуальные итоговые данные.
Метод main не участвует в тестировании.
Написать код проверки самостоятельно в методе main:
1) создать файл, открыть поток на чтение (input stream) и на запись(output stream);
2) создать экземпляр класса Solution — savedObject;
3) записать в поток на запись savedObject (убедитесь, что они там действительно есть);
4) создать другой экземпляр класса Solution с другим параметром;
5) загрузить из потока на чтение объект — loadedObject;
6) проверить, что savedObject.string равна loadedObject.string;
7) обработать исключения.
Требования:
1. Поле pattern должно быть отмечено модификатором transient.
2. Поле currentDate должно быть отмечено модификатором transient.
3. Поле temperature должно быть отмечено модификатором transient.
4. Поле string НЕ должно быть отмечено модификатором transient.
package com.javarush.task.task20.task2014;
import java.text.SimpleDateFormat;
import java.util.Date;
*
Serializable Solution
*
public class Solution {
public static void main(String[] args) {
System.out.println(new Solution(4));
}
private final String pattern = "dd MMMM yyyy, EEEE";
private Date currentDate;
private int temperature;
String string;
public Solution(int temperature) {
this.currentDate = new Date();
this.temperature = temperature;
string = "Today is %s, and current temperature is %s C";
SimpleDateFormat format = new SimpleDateFormat(pattern);
this.string = String.format(string, format.format(currentDate), temperature);
}
@Override
public String toString() {
return this.string;
}
}
*/