Starting from:

$29

Assignment № 1- Implementing a 24-Hour Clock Time Class



Implementing a 24-Hour Clock Time Class
Implement a basic Time class whose objects represent times on the 24-hour clock (00:00 -
23:59) with no exception-handling capability. Also, write a tester class, TimeDemo, that creates
Time objects using the three constructors, modifies them and prints them out in the h:mm:ss
AM/PM format using the printf statement. Generate the API documentation for the Time that
includes private members, constructors and instance methods of the Time class.
The Time Class
The Time class should have hours, minutes and seconds, all integers, as the fields of a time
object. The class should include the following constructors:
• Time(): creates midnight, 00:00:00.
• Time(int h, int m, int s): creates a time object using the specified parameters, where h
represents the hours, m, the minutes, and s, the seconds.
• Time(Time t): creates an object of the Time class equivalent to the specified Time object.
The Time class should have the following instance (accessor and mutator) methods:
• int getHours(): returns the hours in a time object.
• int getMinutes(): returns the minutes in a time object.
• int getSeconds(): returns the seconds in a time object.
• void setTime(int h, int m, int s): modifies a Time object using the specified parameters,
where h represents the hours, m, the minutes, and s, the seconds.
The TimeDemo Class
Write a program, TimeDemo, that does the following:
1. Prompts the user for when class starts.
2. Reads a string representing the 24-hour clock time, parses the string into three integers
representing the hours, minutes and seconds, and uses the parameterized constructor to
create a Time object using the three values.
Assignment № 1 Page 1
3. Using the copy constructor, creates a second Time object that represents when class ends.
Use the start Time as an explicit parameter to the constructor.
4. Using appropriate accessor methods, prints the start time of class in 12-hour clock format.
5. Using appropriate accessor methods, prints the end time of class in 12-hour clock format.
6. Using the mutator, modifies the end time of class using appropriate parameters. Note that
parameters to the mutator are in 24-hour clock format.
7. Again, prints both the start and end time of class in 12-hour clock format using appropriate
accessor methods.
Read the Java online API documentation for the split method in the String class and the Integer.parseInt method in the Integer class. They may be handy when dealing with inputs.
Additional Requirements
Exhaustively, test your program to ensure that it works. Do not test your program using invalid
24-hour clock times. Run the Javadoc utility to make sure that it generates documentation for
the time class. Locate your source files, Time.java and TimeDemo.java, and enclose them in a
zip file, YOURPAWSID_lab01.zip, and submit your lab assignment for grading using the digital
dropbox set up for this purpose. Here are two sample program interactions:
Listing 1: Sample Run 1.
1 Enter when (24-hour clock) class starts - 11:40:00
2
3 Class starts at 11:40:00 AM.
4 Class ends at 11:40:00 AM.
5
6 Enter when (24-hour clock) class ends - 13:00:00
7
8 Class starts at 11:40:00 AM.
9 Class ends at 1:00:00 PM.
Listing 2: Sample Run 2.
1 Enter when (24-hour clock) class starts - 12:05:00
2
3 Class starts at 12:05:00 PM.
4 Class ends at 12:05:00 PM.
5
6 Enter when (24-hour clock) the class ends - 14:00:02
7
8 Class starts at 12:05:00 PM.
9 Class ends at 2:00:02 PM.
Assignment № 1 Page 2

More products