Question: Needs to be in C# Write a countdown alarm clock program that uses delegates to notify anyone who is interested that the designated amount of

Needs to be in C#

Write a countdown alarm clock program that uses delegates to notify anyone who is interested that the designated amount of time has passed. Youll need a class to simulate the countdown clock that accepts a message and a number of seconds to wait (supplied by caller). After waiting the appropriate amount of time, the countdown clock should call the delegate and pass the message to any registered observers. (When you're calculating the time to wait, remember that Thread.Sleep() takes an argument in milliseconds, and requires a using System.Threading statement.) Your countdown clock class should contain a way to create and set the clock appropriate data, a way to start the alarm clock running, a way to pause the alarm clock, a way to resume the countdown, and a way to abort the alarm clock. Create an observer class that echoes the received message to the console. Be certain that the event can be published to multiple handlers safely. Create a driver that demonstrates your program using at least 3-4 observers along with at least 2-3 different usages of the alarm clock with times in the range 3-10 seconds. Be certain that your driver demonstrates the complete functionality of your alarm clock by exercising each of its methods at least once.

I need the pause, stop, start options in my program. Heres what I have so far.

using System.Text;

using System.Threading;

using System.Threading.Tasks;

namespace CountDown

{

public class countDownclock : EventArgs

{

//declare variables

public int timeLeft;

//Constuctor

public countDownclock(int timeLeft)

{

this.timeLeft = timeLeft;

}

}

public class Clock

{

//create local variables

private int timeLeft;

//constructor

public Clock(int timeLeft)

{

this.timeLeft = timeLeft;

}

//method declaration

public delegate void SecondChangedHandler(object theClock, countDownclock countDownLeft);

public SecondChangedHandler SecondChanged;

public void Run()

{

while (this.timeLeft >= 0)

{

countDownclock countDownLeft = new countDownclock(this.timeLeft);

if (SecondChanged != null)

{

SecondChanged(this, countDownLeft);

}

Thread.Sleep(1000);

this.timeLeft--;

}

}

}

//

public class DisplayCountDown

{

//count the number of seconds changed when each second left

public void Subscibe(Clock theClock)

{

theClock.SecondChanged += CountdownTimeLeft;

}

//Display message for every second

public void CountdownTimeLeft(object theClock, countDownclock ti)

{

Console.WriteLine("TimeLeft: {0}", ti.timeLeft.ToString());

}

}

public class TimesUp

{

//Implement the method Subscribe

public void Subscibe(Clock theClock)

{

theClock.SecondChanged += TimesUpCode;

}

//Implement the the method TimesUpCode

public void TimesUpCode(object theClock, countDownclock ti)

{

//If the remaining seconds in 0,Then print the message

if (ti.timeLeft > 0)

{

Console.WriteLine("Times up!");

}

}

}

// Create a class named 'Observer' to test the program.

public class Observer

{

//implement the Run method

public void Run()

{

//Read the number of seconds

int seconds = Convert.ToInt32(Console.ReadLine());

//Instantiate the class

Clock theClock = new Clock(seconds);

//Declare object for

DisplayCountDown countdownObject = new DisplayCountDown();

//call to subscribe

countdownObject.Subscibe(theClock);

//create object for the Launcher class

TimesUp TimesUpObject = new TimesUp();

//call the method with the object

TimesUpObject.Subscibe(theClock);

//call the Run method

theClock.Run();

}

}

class Program

{

static Main(args a)

{

CountDownclock cdc = new CountDownclock();

If(key.Pressed == "p"){

cdc.Pause();

}

If(key.Pressed == "s"){

cdc.Stop();

}

}

}

// Create a class named 'Driver' to execute the program.

class Driver

{

//main method

public static void Main()

{

//Create object for the class

Observer timerobject = new Observer();

//call the Run method

timerobject.Run();

Console.Read();

}

}

}

CountDown class

namespace CountDown

{

internal class CountDownclock

{

class CountdownClock

{

void Stop()

{

}

void Pause()

{

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!