-
Objects programming?
This program produces errors
:9: getHour(int) in Time cannot be applied to ()
System.out.println("The time is:"+time1.getHour()+":"+time1.getMinute()+":"+tim e1.getSecond());
I got stuck at this point of how to pass an integer to the method.
So can someone please give me some advice?
Thanks!
main method
Code:
public class testTime
{
public static void main(String[] args)
{
Time time1 = new Time();
Time time2 = new Time(555550000);
System.out.println("The time is:"+time1.getHour()+":"+time1.getMinute()+":"+time1.getSecond());
System.out.println("The time is:"+time2.getHour()+":"+time2.getMinute()+":"+time2.getSecond());
}//end of main
}//end of testTime
this is a class for time
Code:
public class Time
{
private int hour;
private int minute;
private int second;
public Time()
{
long elTime = System.currentTimeMillis();
// Obtain the total seconds since the midnight, Jan 1, 1970
long totalSeconds = elTime / 1000;
// Compute the current second in the minute in the hour
this.second = (int)(totalSeconds % 60);
// Obtain the total minutes
long totalMinutes = totalSeconds / 60;
// Compute the current minute in the hour
this.minute = (int)(totalMinutes % 60);
// Obtain the total hours
long totalHours = totalMinutes / 60;
// Compute the current hour
this.hour = (int)(totalHours % 24);
}
public Time(long totalMilliseconds)
{
// Obtain the total seconds since the midnight, Jan 1, 1970
long totalSeconds = totalMilliseconds / 1000;
// Compute the current second in the minute in the hour
this.second = (int)(totalSeconds % 60);
// Obtain the total minutes
long totalMinutes = totalSeconds / 60;
// Compute the current minute in the hour
this.minute = (int)(totalMinutes % 60);
// Obtain the total hours
long totalHours = totalMinutes / 60;
// Compute the current hour
this.hour = (int)(totalHours % 24);
}
public static int getHour(int hour)
{
return hour;
}
public static int getMinute(int minute)
{
return minute;
}
public static int getSecond(int second)
{
return second;
}
}//end of time
-
just remove the input parameter of getter method,
those input parameters are meaningless
-
-
get(int) and get() are completely difference method
just like Time() and Time(long) are different
-
i removed the parameter and static of those methods and now its working fine.
Thanks i will make a note of it.