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:

  1. default constructor - initialize  hours, minutes and seconds to zero.
  2. three-argument constructor
  3. setTime to set the time to the time specified by the user.
    public void setTime(int hours, int minutes, int seconds)
  4. getHours returns hours.
    public int getHours()
  5. getMinutes returns minutes
    public int getMinutes()
  6. getSeconds returns seconds
    public int getSeconds()
  7. setHours sets the hours to a new hour value
    void setHours(int h)
  8. setMinutes sets the minutes to a new minute value
    void setMinutes(int m)
  9. setSeconds sets the seconds to a new value
  10. printTime prints the time in the form hh:mm:ss.
    public void printTime()
  11. inputTime inputs a hours, minutes and seconds for a Clock object.
    public void inputTime()
  12. toString() returns a string in the form "hh:mm:ss"
    public String toString()
  13. incrementSeconds increments the time by seconds.
    public void incrementSeconds(int seconds)
  14. incrementMinutes increments the time by  minutes.
    public void incrementMinutes(int minutes)
  15. 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.

  1. Create a Time object called  t1 with hours, minutes and seconds initialized to zero.
  2. Create a Time object called t2 with hours. minutes and seconds initialized to zero.
  3. Create a Time object called t3 with hours, minutes and seconds initialized to 10, 30, and 15 respectively.
  4. 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.
  5. Set the hours, minutes, and seconds for the time object t2 to 20, 12 and 45 respectively using the setTime method.
  6. Display the hours of object t1
  7. Display the minutes of object t2
  8. Display the seconds of object t3
  9. Set the hours of object t1 to 5
  10. Set the minutes of object t2 to 13
  11. Set the seconds of objects t3 to 55
  12. Display the time of object t1 using the printTime method
  13. Display the time of  object t2 using the toString method
  14. Increment the hours of object t1 to 5
  15. Increment the minute of object t1 to 10
  16. Increment the seconds of object t1 to 2
  17. Display the time of object t1 by using the method toString
  18. Create an array of objects called timeArray of type Time with 3 elements.
  19. Store the Time objects t1, t2, t3 in the array timeArray
  20. Display the time of all the objects in the array timeArray.

Grading requirements