using System; /// ThreeClocks shows how to construct 3 clocks /// synchronized to count seconds, minutes, and hours. public class ThreeClocks { Clock hours; Clock minutes; Clock seconds; public ThreeClocks() { hours = new Clock(0); minutes = new Clock(0); seconds = new Clock(0); } public void tick() { seconds.tick(); if ( seconds.getTime() == 60 ) // one full minute? { minutes.tick(); seconds.reset(0); } if ( minutes.getTime() == 60 ) // one full hour? { hours.tick(); minutes.reset(0); } } public string getTime() { return hours.getTime().ToString("00") + ":" + minutes.getTime().ToString("00") + ":" + seconds.getTime().ToString("00"); } }