Last active
February 10, 2016 23:23
-
-
Save FaAway/b68394c41bdadd50343c to your computer and use it in GitHub Desktop.
level20.lesson07.task04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level20.lesson07.task04; | |
import java.io.Serializable; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
/* 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) обработать исключения | |
*/ | |
public class Solution implements Serializable{ | |
public static void main(String[] args) { | |
System.out.println(new Solution(4)); | |
} | |
private transient final 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment