I am trying to make a Clock that displays in 24 hour time, like 00:00:00.
I've created the ReadTime
method in my clock class. In my MainClass
I assumed that if I called the ReadTime
method in a while loop, that it would increase. However the output just stays at 0:0:0.
public class Clock
{
Counter _seconds;
Counter _minutes;
Counter _hours;
public Clock()
{
_seconds = new Counter("Seconds");
_minutes = new Counter("Minutes");
_hours = new Counter("Hours");
}
public void Tick()
{
_seconds.Increment();
if(_seconds.Count>=60)
{
_minutes.Increment();
_seconds.Reset();
}
if(_minutes.Count >= 60)
{
_minutes.Reset();
_hours.Increment();
}
if(_hours.Count >= 24)
{
Reset();
}
}
public void Reset()
{
_hours.Reset();
_minutes.Reset();
_seconds.Reset();
}
public void ReadTime()
{
string ss = _seconds.Count.ToString();
string mm = _minutes.Count.ToString();
string hh = _hours.Count.ToString();
Console.WriteLine("{0:00}:{0:00}:{0:00}", hh, mm, ss);
}
}
This is my main method.
public static void Main(string[] args)
{
Clock ClockDemo = new Clock();
while(true)
{
ClockDemo.Tick();
ClockDemo.ReadTime();
Console.ReadLine();
}
}