anonymous
2009-09-27 11:50:17 UTC
-Data fields hour, minute, and second that represent a time.<---got this one
-A no-arg constructor that creates a Time object for the current time.(the data fields value will represent the current time)<---pretty sure I got this one covered
-A constructor that constructs a Time object with a specified elapsed time since midnight, Jan 1, 1970, in milliseconds, (the data fields value will represent the time) <---- most confused about this
-Three get methods for the data fields<----got this one down
Then I am supposed to write a program that creates two time objects Time() and Time(555550000) and display their hour, minute and second. For the Time(555550000) I have it displaying correctly(10 hours, 19 minutes, 10 seconds). Not sure about the Time(). Here is what I have so far.
public class ex9_1 {
public static void main(String[] args){
Time timetest= new Time(555550000);
System.out.println(timetest.getHour());
System.out.println(timetest.getMinute());
System.out.println(timetest.getSecond());
Time timetest2= new Time();
System.out.println(timetest2.getHour());
System.out.println(timetest2.getMinute());
System.out.println(timetest2.getSecond());
}
}
class Time{
private long hour;
private long minute;
private long second;
private long realhour;
private long realminute;
private long realsecond;
public Time(){
second=System.currentTimeMillis()/1000;
minute=second/60;
hour=minute/60;
realsecond=second%60;
realminute=minute%60;
realhour=hour%24;
}
Time(long millisecond){
second=millisecond/1000;
minute=second/60;
hour=minute/60;
realsecond=second%60;
realminute=minute%60;
realhour=hour%24;
}
public long getHour(){
return this.realhour;
}
public void setHour(long newHour){
this.hour=newHour;
}
public long getMinute(){
return this.realminute;
}
public void setMinute(long newMinute){
this.minute= newMinute;
}
public long getSecond(){
return this.realsecond;
}
public void setSecond(long newSecond){
this.second= newSecond;
}
}
I'm mostly confused about what it is asking for in the time since 1970 thing. Not exactly sure what it is even asking(does it want a separate constructor that is never even called in the test program?). Any feedback is appreciated.