This assignment will introduce you to writing a class to represent a specific topic (a clock) and then work with instances (objects) of that class.
Your task is to create a class called Clock. A clock represents time in hours, minutes, and seconds. The type of time it represents is military time (hours are from 0 to 23, with 0 representing midnight and 23 representing 11pm). Here are the things a user of a Clock object should be able to do:
You are free to add more functionality to your Clock class as you see fit.
Also create a class called ClockTester. This class will contain a main method. From the main method, create a Clock object, then clearly illustrate the specified functionality of the Clock as described above. For any of the set or advance behaviors, get input from the user, then pass this input into the Clock object. After any behavior that modifies the Clock object, be sure and display the time it contains.
SAMPLE RUN (design your program so that it works in a similar fashion)
Welcome to my clock
The current time is 23.58.00
The current hour is 23
Enter a new hour: 33
Invalid hour! Hour not updated
The current time is now 23.58.00
Enter a new minute: 59
The current time is now 23.59.00
Enter a new second: 59
The current time is now 23.59.59
Enter a number to specify how far to advance the hour: 25
The current time is now 0.59.59
Enter a number to specify how far to advance the minute: 61
The current time is now 2.00.59
Enter a starting time for a second clock: 2.00.58
Now comparing the two
clocks for equality:
Their times are different
About to get current time from computer...
The current time is now 19.11.34
Thank you for using the Clock Program!
Recognize there are two fundamental components to this assignment. One is problem solving and the other is class design. You can design your Clock class with pseudo-functional methods -- they don't have to do everything right away. Just think about the data you'll need in the class and the methods that will operate on that data. Furthermore, think about what value(s) must be passed in from outside for a method and what value a method should return. In other words, break the problem down into manageable pieces -- do a little bit at a time.
Your Clock class will need constructors, a toString( ), get and set methods, an equals method, and other methods based on the sample run shown above. The fields your class should contain at the very least are the hour, minute, and second (all type int).
You may assume the user will enter correct data types (ints).
EXTRA CREDIT (10 points) - Design your program so that when the current time is obtained, it properly sets the time based on the time zone of the computer on which it is running. NOTE: You must start with System.currentTimeMillis(), then go from there. You'll need to investigate what other tools the Java API provides
EXTRA CREDIT (5 points) - Read the hour, minute, and second of the second clock in using the format shown in the sample run above (hour followed by a ., followed by the minute, followed by a ., followed by the second)
In comments at the top of ClockTester, place your name, a description of what the program does, and a history of work done on the program. Also use this area to document any items you were unable to complete. You must implement comments in javadoc fashion. Include output captures of your program that demonstrate your program works correctly. At the top of your Clock class, provide a description of what it represents and what it can do.
You should have at least three different runs of the program captured. Place your captured output in a file called output.txt -- this file should be a plain text file.
Submit to blackboard the above files in a .zip file named according to our naming conventions. This is hw6.
Get started ASAP -- you know the game now.