So far we’ve been working with composing shape objects with GUI Java classes. Now we’re going to practice creating a Timer
class that outputs to the console & uses if statements. Your Timer
class will count up from 0 and print “You have no time left!”
Rx: <10 min Av: 10-20 min Sd: 20-30 min DNF: 31+ min
Timer_uLogin
Timer
class with:
tick
method that increments the time elapsed. If the time elapsed is greater than or equal to the limit, print “You have no time left!”time_left
method that returns how much time is left.print
method that prints out useful information for the timer. Think about what information you want to know when you look at a timer that’s counting up.Test your Timer
class by writing a main
method that creates a new Timer
stored in a local variable, timer
, that counts up to 3. Call tick
3 times, printing your timer
’s status after each call. Do you correctly print when there is no time left?
Here is an example output:
Time: 0
Time: 1
Time: 2
You have no time left!
Time: 3
Export > General > Archive File
. Name the file Timer_uLogin.zip
.