In: Computer Science
Programming language is C#
A common place to buy candy is from a machine. A new candy machine has been purchased for the gym , but it is not working properly. The machine sells candies, chips, gum, and cookies. You have been asked to create aprogram for this candy machine so that it can be put into operation. The program should do the following:
1. Show the customer the different products sold by the candy machine. 2. Let the customer make the selection.
3. Show the customer the cost of the item selected.
4. Accept money from the customer.
5. Release the item.
Input The item selection and the cost of the item. Output The selected item.
Note: your program should implement all the concept of Object-Oriented Programming.
The c# code for the given problem statement is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CandyMachine
{
struct Candies
{
public string drinkname;
public string drinkcost;
public string inventory;
}
public partial class VendingMachine : Form
{
public VendingMachine()
{
InitializeComponent();
}
int chipsTotal = 0;
int candiesTotal = 0;
int gumsTotal = 0;
int cookiesTotal = 0;
int sweetcandyTotal=0;
int chipsttotal;
int candiesttotal;
int gumsttotal;
int cookiesttotal;
int sweetcandyttotal;
int EndTotal;
int candiescounter = 20;
int gumsCounter = 20;
int cookiesiesCounter = 20;
int chipsCounter = 20;
int sweetcandycounter = 20;
string[,] candydesc = new string[,] { {"Chips", "1.00", "20"},
{"Candies", "1.00", "20"},
{"Gums", "1.00", "20"},
{"Cookies", "1.50", "20"},
{"Sweet candy", "1.50", "20"} };
Candies Vend;
private void ColaPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = candydesc[0, 0];
Vend.drinkcost = candydesc[0, 1];
Vend.inventory = candydesc[0, 2];
candiescounter = candiescounter - 1;
{
CokeCountLabel.Text = candiescounter.ToString();
if (candiescounter < 1)
{
MessageBox.Show("Sorry Out of Chips");
}
colaTotal = colaTotal + 1;
chipsttotal = colaTotal * 1;
//TotalLabel.Text = chipsttotal.ToString("c");
}
}
private void gumsPictureBox_Click(object sender, EventArgs e)
cookies
Vend.drinkname = candydesc[1, 0];
Vend.drinkcost = candydesc[1, 1];
Vend.inventory = candydesc[1, 2];
gumsCounter = gumsCounter - 1;
cookies
gumsBeerLabel.Text = gumsCounter.ToString();
cookiesgumsCounter cookies
cookies
MessageBox.Show("Sorry Out of gums Beer");
cookies
gumsTotal = gumsTotal +cookies
candiesttotal = gumsTotal * 1;
/cookiestalLabel.Texcookiescandiesttotal.ToString("c");
cookies
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void candiesPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = candydesc[2, 0];
Vend.drinkcost = candydesc[2, 1];
Vend.inventory = candydesc[2, 2];
candiesCounter = candiesCounter - 1;
{
candiesCountLabel.Text = candiesCounter.ToString();
if (candiesCounter < 1)
{
MessageBox.Show("Sorry Out of candies Lime");
}
candiesTotal = candiesTotal + 1;
candiesLimeTotal = candiesTotal * 1;
// TotalLabel.Text = candiesLimeTotal.ToString("c");
}
}
private void chipsPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = candydesc[3, 0];
Vend.drinkcost = candydesc[3, 1];
Vend.inventory = candydesc[3, 2];
chipsCounter = chipsCounter - 1;
{
chipsCountLabel.Text = chipsCounter.ToString();
if (chipsCounter < 1)
{
MessageBox.Show("Sorry Out of chips");
}
chipsTotal = chipsTotal + 1;
cookiesttotal = Vend.inventory*Vend.drinkcost;
// TotalLabel.Text = cookiesttotal.ToString("c");
}
}
private void sweetcandyPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = candydesc[4, 0];
Vend.drinkcost = candydesc[4, 1];
Vend.inventory = candydesc[4, 2];
sweetcandycounter = sweetcandycounter - 1;
{
sweetcandyCountLabel.Text = sweetcandycounter.ToString();
if (sweetcandycounter < 1)
{
MessageBox.Show("Sorry Out of Sweet");
}
sweetcandyTotal = sweetcandyTotal + 1;
sweetcandyttotal = sweetcandyTotal * 1.5;
// TotalLabel.Text = sweetcandyttotal.ToString("c");
}
}
private void TotalPictureBox_Click(object sender, EventArgs e)
{
EndTotal = (chipsttotal + candiesttotal + candiesLimeTotal + cookiesttotal + sweetcandyttotal);
TotalLabel.Text=EndTcookies.ToString("c");
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CandyMachine
{
struct Candies
{
public string drinkname;
public string drinkcost;
public string inventory;
}
public partial class VendingMachine : Form
{
public VendingMachine()
{
InitializeComponent();
}
int chipsTotal = 0;
int candiesTotal = 0;
int gumsTotal = 0;
int cookiesTotal = 0;
int sweetcandyTotal=0;
int chipsttotal;
int candiesttotal;
int gumsttotal;
int cookiesttotal;
int sweetcandyttotal;
int EndTotal;
int candiescounter = 20;
int gumsCounter = 20;
int cookiesiesCounter = 20;
int chipsCounter = 20;
int sweetcandycounter = 20;
string[,] candydesc = new string[,] { {"Chips", "1.00", "20"},
{"Candies", "1.00", "20"},
{"Gums", "1.00", "20"},
{"Cookies", "1.50", "20"},
{"Sweet candy", "1.50", "20"} };
Candies Vend;
private void ColaPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = candydesc[0, 0];
Vend.drinkcost = candydesc[0, 1];
Vend.inventory = candydesc[0, 2];
candiescounter = candiescounter - 1;
{
CokeCountLabel.Text = candiescounter.ToString();
if (candiescounter < 1)
{
MessageBox.Show("Sorry Out of Chips");
}
colaTotal = colaTotal + 1;
chipsttotal = colaTotal * 1;
//TotalLabel.Text = chipsttotal.ToString("c");
}
}
private void gumsPictureBox_Click(object sender, EventArgs e)
cookies
Vend.drinkname = candydesc[1, 0];
Vend.drinkcost = candydesc[1, 1];
Vend.inventory = candydesc[1, 2];
gumsCounter = gumsCounter - 1;
cookies
gumsBeerLabel.Text = gumsCounter.ToString();
cookiesgumsCounter cookies
cookies
MessageBox.Show("Sorry Out of gums Beer");
cookies
gumsTotal = gumsTotal +cookies
candiesttotal = gumsTotal * 1;
/cookiestalLabel.Texcookiescandiesttotal.ToString("c");
cookies
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void candiesPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = candydesc[2, 0];
Vend.drinkcost = candydesc[2, 1];
Vend.inventory = candydesc[2, 2];
candiesCounter = candiesCounter - 1;
{
candiesCountLabel.Text = candiesCounter.ToString();
if (candiesCounter < 1)
{
MessageBox.Show("Sorry Out of candies Lime");
}
candiesTotal = candiesTotal + 1;
candiesLimeTotal = candiesTotal * 1;
// TotalLabel.Text = candiesLimeTotal.ToString("c");
}
}
private void chipsPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = candydesc[3, 0];
Vend.drinkcost = candydesc[3, 1];
Vend.inventory = candydesc[3, 2];
chipsCounter = chipsCounter - 1;
{
chipsCountLabel.Text = chipsCounter.ToString();
if (chipsCounter < 1)
{
MessageBox.Show("Sorry Out of chips");
}
chipsTotal = chipsTotal + 1;
cookiesttotal = Vend.inventory*Vend.drinkcost;
// TotalLabel.Text = cookiesttotal.ToString("c");
}
}
private void sweetcandyPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = candydesc[4, 0];
Vend.drinkcost = candydesc[4, 1];
Vend.inventory = candydesc[4, 2];
sweetcandycounter = sweetcandycounter - 1;
{
sweetcandyCountLabel.Text = sweetcandycounter.ToString();
if (sweetcandycounter < 1)
{
MessageBox.Show("Sorry Out of Sweet");
}
sweetcandyTotal = sweetcandyTotal + 1;
sweetcandyttotal = sweetcandyTotal * 1.5;
// TotalLabel.Text = sweetcandyttotal.ToString("c");
}
}
private void TotalPictureBox_Click(object sender, EventArgs e)
{
EndTotal = (chipsttotal + candiesttotal + candiesLimeTotal + cookiesttotal + sweetcandyttotal);
TotalLabel.Text=EndTcookies.ToString("c");
}
}
}