Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package tictocapp;
  7.  
  8. /**
  9. *
  10. * @author it21814
  11. */
  12. public class Clock {
  13. private int hours;
  14. private int minutes;
  15. private int alarmHours;
  16. private int alarmMinutes;
  17. private int format;
  18. private String name;
  19.  
  20. public Clock (int startHours, int startMinutes, int startAlarmHours, int startAlarmMinutes, int startFormat, String startName) {
  21. hours = startHours;
  22. minutes = startMinutes;
  23. alarmHours = startAlarmHours;
  24. alarmMinutes = startAlarmMinutes;
  25. format = startFormat;
  26. name = startName;
  27. }
  28.  
  29. public int getHours(){
  30. return hours;
  31. }
  32.  
  33. public void setHours(int newHours){
  34. hours = newHours;
  35. }
  36.  
  37. public int getMinutes(){
  38. return minutes;
  39. }
  40.  
  41. public void setMinutes(int newMinutes){
  42. minutes = newMinutes;
  43. }
  44.  
  45. public int getAlarmHours(){
  46. return alarmHours;
  47. }
  48.  
  49. public void setAlarmHours(int newAlarmHours){
  50. alarmHours = newAlarmHours;
  51. }
  52.  
  53. public int getAlarmMinutes(){
  54. return alarmMinutes;
  55. }
  56.  
  57. public void setAlarmMinutes(int newAlarmMinutes){
  58. alarmMinutes = newAlarmMinutes;
  59. }
  60.  
  61. public int getFormat(){
  62. return format;
  63. }
  64.  
  65. public void setFormat(int newFormat){
  66. format = newFormat;
  67. }
  68.  
  69. public String getName(){
  70. return name;
  71. }
  72.  
  73. public void setName(String newName){
  74. name = newName;
  75. }
  76.  
  77. public void TellTime(){
  78. System.out.printf("The time now is %d:%d and the alarm is set for %d:%d\n", hours, minutes, alarmHours, alarmMinutes);
  79. }
  80. public void AdvanceTime(int duration ){
  81. hours+=duration/60;
  82.  
  83. if(minutes + duration%60 >= 60) {
  84. hours+=1;
  85. minutes+=duration%60 - 60;
  86. }
  87. else {
  88. minutes+=duration%60;
  89. }
  90.  
  91. hours%=format;
  92.  
  93. System.out.printf("The time now is %d:%d\n", hours, minutes);
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement