Here i am providing a program to implement coffee vending machine using delegates in c#.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public delegate void vending();
public void hotwater()
{
Console.WriteLine("Please take your hot water.");
}
public void blackcoffe()
{
Console.WriteLine("Please take your balck coffee.");
}
public void cappucino()
{
Console.WriteLine("Please take your cappucino.");
}
static void Main(string[] args)
{
int ch;
char ans;
Program p = new Program();
do
{
Console.WriteLine("Coffee vending machine");
Console.Write("1.Hot Water\n2.Black Coffee\n3.Cappucino\n4.Stop\n\nEnter your choice: ");
ch = Convert.ToInt32(Console.ReadLine());
switch (ch)
{
case 1: vending v = new vending(p.hotwater);
v();
break;
case 2: vending v1 = new vending(p.blackcoffe);
v1();
break;
case 3: vending v2 = new vending(p.cappucino);
v2();
break;
default: break;
}
Console.Write("\nDo u want to continue?(y/n): ");
ans = Convert.ToChar(Console.ReadLine());
} while (ans == 'Y' || ans == 'y');
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment