Created
May 16, 2020 23:03
-
-
Save dan-dm/26d7bc107c5719b8aebc5f712fdcc2e7 to your computer and use it in GitHub Desktop.
Created with Copy to Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Solution for part05-Part05_01.OneMinute | |
src/main/java/ClockHand.java | |
public class ClockHand { | |
private int value; | |
private int limit; | |
public ClockHand(int limit) { | |
this.limit = limit; | |
this.value = 0; | |
} | |
public void advance() { | |
this.value = this.value + 1; | |
if (this.value >= this.limit) { | |
this.value = 0; | |
} | |
} | |
public int value() { | |
return this.value; | |
} | |
public String toString() { | |
if (this.value < 10) { | |
return "0" + this.value; | |
} | |
return "" + this.value; | |
} | |
} | |
src/main/java/Program.java | |
import java.util.Scanner; | |
public class Program { | |
public static void main(String[] args) { | |
// You can test your program here | |
} | |
} | |
src/main/java/Timer.java | |
public class Timer { | |
private ClockHand seconds; | |
private ClockHand hundredths; | |
public Timer() { | |
this.seconds = new ClockHand(60); | |
this.hundredths = new ClockHand(100); | |
} | |
public void advance() { | |
this.hundredths.advance(); | |
if (this.hundredths.value() == 0) { | |
this.seconds.advance(); | |
} | |
} | |
@Override | |
public String toString() { | |
return this.seconds + ":" + this.hundredths; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment