CIS 162 |
Lab 4: Simple Time |
Fall 2018 |
After completing this lab, you should be able to:
Write a new class that represents the time of day:
SimpleTime
(It is important that you use the name
SimpleTime
.)
public SimpleTime(int h, int m, int s)
- this constructor initializes the three instance
variables
public SimpleTime( )
- this default constructor initializes the three instance variables
midnight
public boolean isMidnight( )
- return true if the current time is 0:00:00public boolean isNoon( )
- return true if the current time is 12:00:00public boolean isLunchTime( )
- return true if the current time is between 12:00:00 and
13:00:00
(inclusive)
public String toString ( )
- use the three instance variables to build a String representation
of the time. For example, 14:12:56.
public void increment ( )
- increases the current time by one second. Pay attention to end of
rollovers of seconds and minutes.
As you complete each method, use BlueJ's object inspector to verify that your methods are correct.
When you have completed all the methods above,
SimpleTimeTest.java
and
add it to your project's folder.
Tools => Testing => Run Tests
to run the unit tests.
When your code passes all of the unit tests
Add this method public int secondsElapsed(SimpleTime start)
that will calculate the number of seconds
that have elapsed between start
and the time represented by the current object. Add test methods to
SimpleTimeTest
to verify that your code is correct.