Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.