如何创建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
this time.)
■ A constructor that constructs a Time object with the specified hour, minute, and
second.
■ 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,
ShowCurrentTime.java.)

weilin

以下是解答
import java.util.Date;
import java.util.Calendar;
public class Time {

long hour,minute,second;
Date date;
Calendar calendar=Calendar.getInstance();
public Time(){
    this.date=new Date();   
}
public Time(long milliseconds){
    this.date=new Date(milliseconds);   
}
public Time(int hour,int minute,int second){
    long sum=0;
    sum=sum+hour*60*60*1000+minute*60*1000+second*1000;
    this.date=new Date(sum);
}
public long getHour() {
    hour=date.getTime()/3600000;
    return hour;
}
public long getMinute(){
     minute = (date.getTime() % 3600000) / 60000;
return minute;

}
public long getSecond() {
     second= (date.getTime() % 3600000) % 60000/1000;
    return second;  
}
public void setTime(long elapseTime) {
    Date newdate=new Date(elapseTime);
    date=newdate;   
}   

}

测试

public class Test {
public static void main(String args[]) {
Time time1=new Time();
Time time2=new Time(555550000);

    //System.out.println(time1.date);
    //System.out.println(time2.date);
    System.out.println("new Time()时分秒为:"+time1.getHour()+"时"+time1.getMinute()+"分"+time1.getSecond()+"秒");
    System.out.println("new Time(555550000)时分秒为:"+time2.getHour()+"时"+time2.getMinute()+"分"+time2.getSecond()+"秒");
}   

}