Java program that contains a class named Clock

Order Description

Create a Java program that contains a class named Clock.  The program should be saved to a file named Chapter 04 Extra Credit.

 

The clock class has 3 instance variables:

 

·         hr that holds the clock hour in the range 0 – 23; type int

 

·         min that holds the clock minute in the range 0 – 59; type int

 

·         sec that holds the clock second in the range 0 – 59; type int

 

The class should also have 2 constructors:

 

·         The default constructor

 

·         A constructor with three parameters (hour, minute and second) all int

 

The class should have the following methods:

 

·         setTime that has three integer parameters and sets the hour minute and second.  This method needs to check to make sure the values are in the proper range as stated above.  If a value is out of range, set its variable to 0.

 

·         printTime that prints the clock time in the format hh:mm:ss

 

·         getHour that returns the hour value

 

·         getMinute that returns the minute value

 

·         getSecond that returns the second value

 

·         incrementTime that increments the second value by 1 second.  If the second value goes to 60, the minute value should increase by 1 and the second value should be set to 0.  If the minute value goes to 60, the hour value should increase by 1 and the minute value should be set to 0.  If the hour value goes to 24, the hour value should be set to 0.

 

 

 

The Java program should also have a mainClock class that runs a test program.  Test all the features of the clock class.