Every computer needs to have some notion of the current time. Some programs need the current date and time, while others may record the time required to perform some task. For either application the basic process of storing the time and the methods required to use and manipulate that time are almost the same.
In this assignment you will write a Java class named TimeCounter. The TimeCounter class provides a way to store, change, and retrieve the time. One of the things that we need to decide about this class is how it will store the time. One way to do this would be to store the number of hours, minutes, and seconds after midnight. This technique works fine unless you need to convert the time into different formats. Most computers display the time based on the time zone in which the computer is located. A computer in Rochester uses Eastern Standard Time(EST), whereas a computer in San Francisco uses Pacific Standard Time (PST). Conversions of time into different representations is much easier if the time is stored as the number of seconds past some well known date and time. Most Unix systems store time as the number of seconds that have elapsed since January 1, 1970 (Windows 95 stores time as the number of seconds since January 1, 1980).
The TimeCounter class that you will write will store the time in tenths of seconds. In other words, your TimeCounter will have only one data member that stores time in tenths of a second. This will give the class the ability to easily convert time into different formats, and it allow us to record time to the nearest 10th of a second. The class will also provide methods to set, change, and obtain the time in hours, minutes, and seconds. The Javadoc page that gives the specifications for each of the methods in the TimeCounter class can be found here.
Download and unpack the jar file that contains the code you will need to complete this assignment.
To unpack the archive type the following command:
jar xf
miniass1.jar
Now write a compilable class stub for the TimeCounter class (if you have not read the information on class stubs you might not know what a stub is). Refer to the Javadoc pages for the TimeCounter class to determine what the headings for each of the methods should look like. Remember for any method that is a function you must include a return statement to get your class to compile. As always, any code that you write must adhere to the Sun's Java coding standard.
Once your stub compiles check to see if you got it right by compiling and running the program TestStub.java. The source code for the TestStub program is included in the miniass1.jar file that you downloaded.
Take a few minutes to look at the contents of the file TestStub.java. Note that the program does not do anything useful, but it does use every method in the TimeCounter class. The following command will compile the TestStub program with your TimeCounter class stub:
javac TimeCounter.java TestStub.java
Any errors that the compiler reports are the result of your TimeCounter class stub. Find the errors and correct them.