Guest User

Untitled

a guest
Jul 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. public class Clock
  2. {
  3. private static final int HOUR_TO_SECONDS = 3600;
  4. private static final int MINUTE_TO_SECONDS = 60;
  5. private static final int DAY_TO_HOUR = 24;
  6.  
  7. private int hours;
  8. private int minutes;
  9. private int seconds;
  10.  
  11. //initializing clock to 0
  12. public Clock()
  13. {
  14. hours = 0;
  15. minutes = 0;
  16. seconds = 0;
  17. }
  18.  
  19. public Clock(int hours, int minutes, int seconds)
  20. {
  21. this.hours = hours;
  22. this.minutes = minutes;
  23. this.seconds = seconds;
  24. }
  25. //setting parameters for clock(not going over 60)
  26. public Clock(int totalSeconds)
  27. {
  28. hours = (totalSeconds / HOUR_TO_SECONDS % DAY_TO_HOUR);
  29. minutes = (totalSeconds % HOUR_TO_SECONDS / MINUTE_TO_SECONDS);
  30. seconds = (totalSeconds % MINUTE_TO_SECONDS);
  31. }
  32. //adding a tick to seconds
  33. public void tick()
  34. {
  35. int totalSeconds;
  36. totalSeconds = hours * 3600 + minutes* 60 + seconds;
  37. totalSeconds++;
  38. hours = (totalSeconds / HOUR_TO_SECONDS % DAY_TO_HOUR);
  39. minutes = (totalSeconds % HOUR_TO_SECONDS / MINUTE_TO_SECONDS);
  40. seconds = (totalSeconds % MINUTE_TO_SECONDS);
  41. }
  42.  
  43. public Clock addClock(Clock Cl)
  44. {
  45. Clock testClock;
  46. int totalSeconds, totalSecondsCl;
  47. totalSeconds = (hours + HOUR_TO_SECONDS) + (minutes + MINUTE_TO_SECONDS) + seconds;
  48. totalSecondsCl =(Cl.hours + HOUR_TO_SECONDS) + (Cl.minutes + MINUTE_TO_SECONDS) + Cl.seconds;
  49. totalSeconds += totalSecondsCl;
  50. testClock = new Clock(totalSeconds);
  51. return testClock;
  52. }
  53.  
  54. public static void main(String[] args)
  55. {
  56. Clock Cl1, Cl2, Cl3;
  57. Cl1 = new Clock(1, 2, 3);
  58. Cl2 = new Clock(4,5,6);
  59. Cl3 = Cl1.addClock(Cl2);
  60. }
  61. //time zone
  62. public String getTimeZones()
  63. {
  64. retun TimeZones;
  65. }
  66.  
  67. public void Clock(int timeZone)
  68. {
  69. int timeZone;
  70. }
  71.  
  72. public static void main(String[] args)
  73. {
  74. timezone timezone1, timezone2,timezone3;
  75. timezone1 = new timezone( );
  76. timezone1.setregion("newyork");
  77.  
  78. timezone2 = new timezone( );
  79. timezone2.setregion("Kiev");
  80.  
  81. timezone3 = new timezone( );
  82. timezone3.setregion("LA");
  83. }
  84. }
Add Comment
Please, Sign In to add comment