Create a Java program that contains a class named Clock (java)

profileDfee
Chapter04.docx

CS 166 02

Extra Credit Assignment 01 Chapter 04

10 Points

Name ____________________________________

Due: Tuesday, October 9, 2018

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.

Add the following comments to the top of your source code:

Name

Class and Section (CS 166 02)

Assignment: Extra Credit 01 Chapter 04

Due Date: (see above)

Description of the program

What to turn in

1. Print out the source code for all files created.

2. Attach this sheet to the front of all printouts and turn in at class time.

3. Copy the Chapter 04 Extra Credit folder into your folder in the I:\kopp\inbox\CS 166 02 folder.