Question

In: Computer Science

Programming language is C# A common place to buy candy is from a machine. A new...

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.

Solutions

Expert Solution

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");
        }

        }
    }

Related Solutions

C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
In C Programming Language Write a program to output to a text log file a new...
In C Programming Language Write a program to output to a text log file a new line starting with day time date followed by the message "SUCCESSFUL". Please screenshot the results.
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates....
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates. The dipping operation currently is done largely by hand. The machine the company is considering costs $150,000. The manufacturer estimates that the machine would be usable for five years but would require the replacement of several key parts at the end of the third year. These parts would cost $9,600, including installation. After five years, the machine could be sold for $7,000. The company...
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates....
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates. The dipping operation currently is done largely by hand. The machine the company is considering costs $180,000. The manufacturer estimates that the machine would be usable for five years but would require the replacement of several key parts at the end of the third year. These parts would cost $9,900, including installation. After five years, the machine could be sold for $5,000. The company...
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates....
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates. The dipping operation currently is done largely by hand. The machine the company is considering costs $120,000. The manufacturer estimates that the machine would be usable for five years but would require the replacement of several key parts at the end of the third year. These parts would cost $9,300, including installation. After five years, the machine could be sold for $4,000. The company...
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates....
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates. The dipping operation is currently done largely by hand. The machine the company is considering costs $200,000. The manufacturer estimates that the machine would be usable for five years but would require the replacement of several key parts at the end of the third year. These parts would cost $10,100, including installation. After five years, the machine could be sold for $9,000.       The company...
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates....
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates. The dipping operation currently is done largely by hand. The machine the company is considering costs $150,000. The manufacturer estimates that the machine would be usable for five years but would require the replacement of several key parts at the end of the third year. These parts would cost $9,600, including installation. After five years, the machine could be sold for $7,000. The company...
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates....
The Sweetwater Candy Company would like to buy a new machine that would automatically “dip” chocolates. The dipping operation currently is done largely by hand. The machine the company is considering costs $260,000. The manufacturer estimates that the machine would be usable for five years but would require the replacement of several key parts at the end of the third year. These parts would cost $10,700, including installation. After five years, the machine could be sold for $10,000. The company...
In the C programming language, implement the translation from regular English to Euroglish. If the letters...
In the C programming language, implement the translation from regular English to Euroglish. If the letters were uppercase, keep them uppercase in the replacement. 1. Remove one“e”from the end of words that are more than three characters long, if they happen to end in “e”. 2. Change all double letters to a single letter (including double spaces). Do not remove double line spacing (i.e. “\n”). 3. When a word ends in “ed”, change that to just “d”. Text: The cat...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT