
Patrick B. answered 09/29/20
Math and computer tutor/teacher
class TTime
{
private int second;
private int hour;
private int minute;
// time values are assumed valid
public TTime ( int h, int m, int s)
{
hour = h; minute=m; second=s;
}
public int GetHour() { return(hour); }
public int GetMinute() { return(minute); }
public int GetSecond() { return(second); }
public void SetHour( int h) { hour=h; }
public void SetMinute( int m) { minute = m; }
public void SetSecond( int s) { second=s; }
public String toString()
{
String outbuff="0";
if (hour<10)
{
outbuff = outbuff+hour;
}
else
{
outbuff = ""+hour;
}
outbuff = outbuff + ":";
if (minute<10)
{
outbuff = outbuff + "0" + minute;
}
else
{
outbuff = outbuff + minute;
}
outbuff = outbuff + ":";
if (second<10)
{
outbuff = outbuff + "0" + second;
}
else
{
outbuff = outbuff + second;
}
return(outbuff);
}
public void SetTime ( int h, int m, int s)
{
hour=h; minute=m; second=s;
}
public TTime( TTime t) //copy constructor
{
this.second = t.GetSecond();
this.minute = t.GetMinute();
this.hour = t.GetHour();
}
public TTime nextSecond()
{
second++;
if (second==60)
{
minute++;
second=0;
}
if (minute==60)
{
hour++;
minute=0;
}
if (hour==24)
{
//increases the day
hour=0;
}
return(this);
}
public static void main(String args[])
{
TTime t = new TTime(0,0,0);
do
{
System.out.println( t.toString());
TTime T = t.nextSecond();
t = T;
}
while (!((t.GetHour()==0) && (t.GetMinute()==0) && (t.GetSecond()==0)));
}
}