Advertisement
rmword

Untitled

Oct 12th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. /**
  2. * @author Rifqi Mukti W
  3. * @version 2017.10.12
  4. */
  5. public class ClockDisplay
  6. {
  7. private NumberDisplay hours;
  8. private NumberDisplay minutes;
  9. private String displayString;
  10.  
  11. /**
  12. * Constructor ini membuat jam yg di-set saat 00:00
  13. */
  14. public ClockDisplay()
  15. {
  16. hours = new NumberDisplay(24);
  17. minutes = new NumberDisplay(60);
  18. updateDisplay();
  19. }
  20.  
  21. /**
  22. * Constructor ini membuat jam yang di-set sesuai parameter
  23. */
  24. public ClockDisplay(int hour, int minute)
  25. {
  26. hours = new NumberDisplay(24);
  27. minutes = new NumberDisplay(60);
  28. setTime(hour, minute);
  29. }
  30.  
  31. /**
  32. * Method ini membuat display clock bertambah satu menit
  33. */
  34. public void timeTick()
  35. {
  36. minutes.increment();
  37. if(minutes.getValue() == 0) {
  38. hours.increment();
  39. }
  40. updateDisplay();
  41. }
  42.  
  43. /**
  44. * Mengatur waktu display ke jam dan menit yang spesifik
  45. */
  46. public void setTime(int hour, int minute)
  47. {
  48. hours.setValue(hour);
  49. minutes.setValue(minute);
  50. updateDisplay();
  51. }
  52.  
  53. /**
  54. * Return waktu sekarang di display dengan format HH:MM.
  55. */
  56. public String getTime()
  57. {
  58. return displayString;
  59. }
  60.  
  61. /**
  62. * Update string untuk display.
  63. */
  64. private void updateDisplay()
  65. {
  66. int hour = hours.getValue();
  67. String suffix;
  68.  
  69. if(hour>=12){
  70. suffix = "pm";
  71. }
  72. else {
  73. suffix = "am";
  74. }
  75.  
  76. if(hour>=12){
  77. hour-=12;
  78. }
  79.  
  80. if(hour==0){
  81. hour = 12;
  82. }
  83.  
  84. displayString = hour + ":" +
  85. minutes.getDisplayValue() + suffix;
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement