xinyu_Tiffany 于 2014.07.22 00:38 提问
- 如何创建Time class，求解一道题
(The Time class) Design a class named Time. The class contains:
■ Data fields hour, minute, and second that represent a time.
■ A no-arg constructor that creates a Time object for the current time. (The values
of the data fields will represent the current time.)
■ A constructor that constructs a Time object with a specified elapsed time since
midnight, Jan 1, 1970, in milliseconds. (The values of the data fields will represent
■ A constructor that constructs a Time object with the specified hour, minute, and
■ Three get methods for the data fields hour, minute, and second, respectively.
■ A method named setTime(long elapseTime) that sets a new time for the
object using the elapsed time.
Implement the class. Write a test program
that creates two Time objects (using new Time() and new Time(555550000))
and display their hour, minute, and second.
(Hint: The first two constructors will extract hour, minute, and second from the
elapsed time. For example, if the elapsed time is 555550 seconds, the hour is 10,
the minute is 19, and the second is 9. For the no-arg constructor, the current time
can be obtained using System.currentTimeMills(), as shown in Listing 2.6,