Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import java.util.*;
  2. import java.time.*;
  3.  
  4. class Clock {
  5.  
  6. LocalTime time;
  7.  
  8. public Clock (int hour, int minute) {
  9.  
  10. this.time = LocalTime.of (hour, minute);
  11.  
  12. }
  13.  
  14. public LocalTime getTime() {
  15.  
  16. return time;
  17.  
  18. }
  19.  
  20. public String toString() {
  21.  
  22. return String.valueOf(time);
  23.  
  24. }
  25.  
  26. public LocalTime addMinutes (int minutes) {
  27.  
  28. time = time.plusMinutes(minutes);
  29.  
  30. return time;
  31.  
  32. }
  33.  
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40. class Program {
  41.  
  42. public static void main (String[] args) {
  43.  
  44. List<Clock> clocks = new LinkedList<>();
  45.  
  46. clocks.add (new Clock (12, 15));
  47. clocks.add (new Clock (14, 25));
  48. clocks.add (new Clock (17, 34));
  49. clocks.add (new Clock (23, 59));
  50.  
  51. System.out.println(clocks);
  52.  
  53. List<Clock> clocksAfterAddMinutes = new LinkedList<>();
  54.  
  55. for (int i=0; i<clocks.size(); i++) {
  56.  
  57. System.out.println(clocks.get(i).addMinutes(1));
  58.  
  59. };
  60.  
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement