Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. package com.javarush.task.task20.task2014;
  2.  
  3. import java.io.*;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6.  
  7. /*
  8. Serializable Solution
  9. */
  10. public class Solution implements Serializable{
  11. public static void main(String[] args) throws Exception{
  12. System.out.println(new Solution(4));
  13. FileOutputStream fs = new FileOutputStream("test.txt");
  14. ObjectOutputStream os = new ObjectOutputStream(fs);
  15. FileInputStream fi = new FileInputStream("test.txt");
  16. ObjectInputStream oi = new ObjectInputStream(fi);
  17.  
  18. Solution savedObject = new Solution(5);
  19. os.writeObject(savedObject);
  20. Solution loadedObject = new Solution(6);
  21. if(loadedObject.temperature == savedObject.temperature){savedObject = loadedObject;}
  22.  
  23. System.out.println(savedObject);
  24. }
  25.  
  26. private final transient String pattern = "dd MMMM yyyy, EEEE";
  27. private transient Date currentDate;
  28. private transient int temperature;
  29. String string;
  30.  
  31. public Solution(int temperature) {
  32. this.currentDate = new Date();
  33. this.temperature = temperature;
  34.  
  35. string = "Today is %s, and current temperature is %s C";
  36. SimpleDateFormat format = new SimpleDateFormat(pattern);
  37. this.string = String.format(string, format.format(currentDate), temperature);
  38. }
  39.  
  40. @Override
  41. public String toString() {
  42. return this.string;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement