Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Rifqi Mukti W
- * @version 2017.10.12
- */
- public class ClockDisplay
- {
- private NumberDisplay hours;
- private NumberDisplay minutes;
- private String displayString;
- /**
- * Constructor ini membuat jam yg di-set saat 00:00
- */
- public ClockDisplay()
- {
- hours = new NumberDisplay(24);
- minutes = new NumberDisplay(60);
- updateDisplay();
- }
- /**
- * Constructor ini membuat jam yang di-set sesuai parameter
- */
- public ClockDisplay(int hour, int minute)
- {
- hours = new NumberDisplay(24);
- minutes = new NumberDisplay(60);
- setTime(hour, minute);
- }
- /**
- * Method ini membuat display clock bertambah satu menit
- */
- public void timeTick()
- {
- minutes.increment();
- if(minutes.getValue() == 0) {
- hours.increment();
- }
- updateDisplay();
- }
- /**
- * Mengatur waktu display ke jam dan menit yang spesifik
- */
- public void setTime(int hour, int minute)
- {
- hours.setValue(hour);
- minutes.setValue(minute);
- updateDisplay();
- }
- /**
- * Return waktu sekarang di display dengan format HH:MM.
- */
- public String getTime()
- {
- return displayString;
- }
- /**
- * Update string untuk display.
- */
- private void updateDisplay()
- {
- int hour = hours.getValue();
- String suffix;
- if(hour>=12){
- suffix = "pm";
- }
- else {
- suffix = "am";
- }
- if(hour>=12){
- hour-=12;
- }
- if(hour==0){
- hour = 12;
- }
- displayString = hour + ":" +
- minutes.getDisplayValue() + suffix;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement