CIS 174 LAB
ASSIGNMENT #11
Assigned date: Thursday 4/22
Due date:Thursday 5/1
30 points
1. Design and implement the class Clock to implement the time of day
in a program. Suppose that the time is represented as set of three integer data
members: one to represent the hours, one to represent the minutes, and one to
represent the seconds. The program must perform the following operations:
- default constructor - initialize hours, minutes and seconds
to zero.
- three-argument constructor
- setTime to set the time to the time specified by the user.
public void setTime(int hours, int minutes, int seconds)
- getHours returns hours.
public int getHours()
- getMinutes returns minutes
public int getMinutes()
- getSeconds returns seconds
public int getSeconds()
- setHours sets the hours to a new hour value
void setHours(int h)
- setMinutes sets the minutes to a new minute value
void setMinutes(int m)
- setSeconds sets the seconds to a new value
- printTime prints the time in the form hh:mm:ss.
public void printTime()
- inputTime inputs a hours, minutes and seconds for a Clock object.
public void inputTime()
- toString() returns a string in the form "hh:mm:ss"
public String toString()
- incrementSeconds increments the time by seconds.
public void incrementSeconds(int seconds)
- incrementMinutes increments the time by minutes.
public void incrementMinutes(int minutes)
- incrementHours increments the time by hours
public void incrementHours(in hours)
Write the main method to test all the object methods in the class Time.
- Create a Time object called t1 with hours, minutes and
seconds initialized to zero.
- Create a Time object called t2 with hours. minutes and seconds
initialized to zero.
- Create a Time object called t3 with hours, minutes and seconds
initialized to 10, 30, and 15 respectively.
- Call the method inputTime to input hours, minutes and seconds
for the Time object t1.
Input hours, minutes, seconds to 13, 40 and 20 respectively.
- Set the hours, minutes, and seconds for the time object t2 to
20, 12 and 45 respectively using the setTime method.
- Display the hours of object t1
- Display the minutes of object t2
- Display the seconds of object t3
- Set the hours of object t1 to 5
- Set the minutes of object t2 to 13
- Set the seconds of objects t3 to 55
- Display the time of object t1 using the printTime method
- Display the time of object t2 using the toString method
- Increment the hours of object t1 to 5
- Increment the minute of object t1 to 10
- Increment the seconds of object t1 to 2
- Display the time of object t1 by using the method toString
- Create an array of objects called timeArray of type Time with 3
elements.
- Store the Time objects t1, t2, t3 in the array timeArray
- Display the time of all the objects in the array timeArray.
Grading requirements
-
A copy of Javadoc document
-
Demonstrate the lab problem to the instructor in the lab.
-
A hard copy of your lab assignment report.