creating a Time class using System.currentTimeMillis() - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

creating a Time class using System.currentTimeMillis()

Hello,

1st post on this forum...

I am making a class called Time where I use System.currentTimeMillis() to display the current time. Then I create another constructor to get the time using 555550000 elapsed milliseconds. I have created both a Time class and a UseTime class. When I use the UseTime class, it gives me 0 hours, 0 minutes, and counts the seconds. I am trying to debug. My 1st debug is to test the Time class to see if it actually gives the correct time. But how do I use a println statement in the Time class to test it out?

Below is my code. Any help here is appreciated.

[code]public class Time{

//Obtain the total milliseconds since midnight, Jan 1, 1970
private long totalMilliseconds;
private long totalSeconds;
private long currentSecond;
private long totalMinutes;
private long currentMinute;
private long totalHours;
private long currentHour;

/*
Default constructor
/
*/

public Time()
{
totalMilliseconds = System.currentTimeMillis();
totalSeconds = totalMilliseconds / 1000;
currentSecond = (int)(totalSeconds % 60);
totalMinutes = currentSecond / 60;
currentMinute = totalMinutes % 60;
totalHours = totalMinutes / 60;
currentHour = totalHours % 24;
}

public Time(long newTotalMilliseconds, long newTotalSeconds, long newCurrentSecond, long newTotalMinutes, long newCurrentMinute,
long newTotalHours, long newCurrentHour)
{
totalMilliseconds = newTotalMilliseconds;
totalSeconds = newTotalSeconds;
currentSecond = newCurrentSecond;
totalMinutes = newTotalMinutes;
currentMinute = newCurrentMinute;
totalHours = newTotalHours;
currentHour = newCurrentHour;
}

//getter
public long getTotalMilliseconds ()
{
return totalMilliseconds;
}

//setter
public void setTotalMilliseconds(long newTotalMilliseconds)
{
totalMilliseconds = newTotalMilliseconds;
}

//getter
public long getTotalSeconds ()
{
return totalSeconds;
}

//setter
public void setTotalSeconds(long newTotalSeconds)
{
totalSeconds = newTotalSeconds;
}

//getter
public long getCurrentSecond()
{
return currentSecond;
}

//setter
public void setCurrentSecond(long newCurrentSecond)
{
currentSecond = newCurrentSecond;
}

//getter
public long getTotalMinutes()
{
return totalMinutes;
}

//setter
public void setTotalMinutes(long newTotalMinutes)
{
totalMinutes = newTotalMinutes;
}

//getter
public long getCurrentMinute()
{
return currentMinute;
}

//setter
public void setCurrentMinute(long newCurrentMinute)
{
currentMinute = newCurrentMinute;
}

//getter
public long getTotalHours()
{
return totalHours;
}

//setter
public void setTotalHours(long newTotalHours)
{
totalHours = newTotalHours;
}

//getter
public long getCurrentHour()
{
return currentHour;
}

//setter
public void setCurrentHour(long newCurrentHour)
{
currentHour = newCurrentHour;
}

//toString method
public String toString()
{
return "The current time is " + getCurrentHour() + ":" + getCurrentMinute() + ":" + getCurrentSecond();
}

}[/code]
Sign In or Register to comment.