Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hey guys! please help me with this project...for c# Vending Machine Simulator Co

ID: 3793678 • Letter: H

Question

hey guys!

please help me with this project...for c#

Vending Machine Simulator Console Application Write a C# Visual Studio Console Application that will mimic a vending machine.   Do not change the name of Program.cs.   Create a class VendingItem.cs (not in Program.cs) to hold the following properties.  Item, Price, Location, Quantity In addition to the properties in the class create a method in the class called ReduceInventory() that deducts one from the inventory when the item is purchased. In Program.cs Create a method called FillMachine() that will instantiate objects of type VendingItem for each item. Fill the machine with the following items: Item              Price        Location      Quantity   Pepsi 20 oz           2.25        A1        6   Sierra Mist 20 oz        2.25        A2        5   Diet Pepsi 20 oz         2.25        A3        5   Snapple Lemon tea 16 oz      1.55        B1       7   Snapple Diet Lemon tea 16 oz     1.55        B2        6   Snapple Raspberry tea 16 oz      1.55       B3        3   Lays Potato Chips        1.15        C1        6   Cheetos          1.05        C2        5   Doritos Cool Ranch        1.25        C3        8   Twix Bar            .95        D1        6   KitKat              .95        D2        5   Twizzlers            .85        D3        2   Juicy Fruit Gum           .55        E1        9   TicTacs            .90        E2        8   Doublemint Gum          .65        E3        4   Store these items in a List of VendingItem called items. Call this method from main when the program first starts. Create a method called DisplayMachine() which will create the text representation of the vending machine. You’re going to display for the user a menu neatly formatted in a way that visualizes a vending machine with the name of each item, the price and quantity on hand. Here is an example I put together: The first thing you’ll ask the user is for how much they are putting in the machine. Your machine will only take paper money in the following denominations: 1s, 2s, and 5s. The machine only takes one bill per transaction so if they want to buy a soda for 2.25 then they have to put in a fivedollar bill.    Likewise, they can use a fivedollar bill for any transaction with the machine returning $1 coins for the change for dollars.    Next ask them to make a selection. At this point display, how much they’ve entered in the machine along with the prompt to make a selection. Once they make their selection check to make sure they have inserted enough money for the purchase. If they haven’t entered enough money, then tell them that you’re refunding their money due to the price being too much for the amount of money they’ve inserted and no selection was vended.  Here are some screen shots: Here they’ve inserted $1.00. Next, they’ll attempt to choose a1 which is an item that costs $2.25: And here is the result. The user is told that they have not inserted enough for that item, their money is returned, and nothing is vended.    If the amount of money they’ve inserted is more than the price of the item, then check the quantity on hand for the item (stored in the object) and if it is zero then inform the user that there are none of those items available and prompt them to make another selection. When they select an item that is in stock call a method in Program.cs called MakeChange().   You’ll pass the object and money amount into MakeChange() and return a string to display to the screen with their change. This method will deduct the price of the item from the amount they’ve entered and make change for them. When you make change, you’ll check for dollars first, then quarters, then dimes, and then nickels. Our machine doesn’t use pennies. Return the change to display for the user and tell them that their item was vended.  At this point call ReduceInventory() for that object (internal method) to deduct one from the inventory. Immediately show the difference in quantity in the vending machine menu. (Call DisplayMachine() again). You’re always going to display the vending machine menu for the user.

Explanation / Answer

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace P04VendingMachine
{
    class Program
    {
        public static int winHeight;
        public static int winWidth;
        public static List <VendingItemClass> items;
        public static bool running;
        public static string input;
        public static double balance;

        static void Main(string[] args)
        {

            init();
            do
            {
                displayMachine();
                Console.Write(" Insert a Bill($1, $2, $5, or 0 to end): ");
                input = Console.ReadLine();
                switch(input)
                {
                    case "1":
                        displayMachine();                      
                        balance = 1;
                        buyItem();
                        break;
                    case "2":
                        displayMachine();
                        balance = 2;
                        buyItem();
                        break;
                    case "5":
                        displayMachine();
                        balance = 5;
                        buyItem();
                        break;
                    case "0":
                        running = false;
                        break;
                    default:
                        break;
                }

            } while (running);
         
        }
        public static void init()
        {
            fillMachine();
            winWidth = 120;
            winHeight = 30;
            Console.SetWindowSize(winWidth, winHeight);
            running = true;
            balance = 0;
        }

        public static void fillMachine()
        {
            items = new List<VendingItemClass>();
            items.Add(new VendingItemClass("Pepsi 20oz", 2.25, "A1", 6));
            items.Add(new VendingItemClass("Sierra Mist 20oz", 2.25, "A2", 5));
            items.Add(new VendingItemClass("Diet Pepsi 20oz", 2.25, "A3", 5));
            items.Add(new VendingItemClass("Snapple Lemon tea 16oz", 1.55, "B1", 7));
            items.Add(new VendingItemClass("Snapple Diet Lemon tea 16oz", 1.55, "B2", 6));
            items.Add(new VendingItemClass("Snapple Raspberry tea 16oz", 1.55, "B3", 3));
            items.Add(new VendingItemClass("Lays Potato Chips", 1.15, "C1", 6));
            items.Add(new VendingItemClass("Cheetos", 1.05, "C2", 5));
            items.Add(new VendingItemClass("Doritos Cool Ranch", 1.25, "C3", 8));
            items.Add(new VendingItemClass("Twix Bar", 0.95, "D1", 6));
            items.Add(new VendingItemClass("Kit-Kat", 0.95, "D2", 5));
            items.Add(new VendingItemClass("Twizzlers", 0.85, "D3", 2));
            items.Add(new VendingItemClass("Juicy Fruit Gum", 0.55, "E1", 9));
            items.Add(new VendingItemClass("Tic-Tacs", 0.90, "E2", 8));
            items.Add(new VendingItemClass("Doublemint Gum", 0.65, "E3", 4));
        }

        public static void displayMachine()
        {
            Console.Clear();
            Console.WriteLine("Vending Machine");
            for (int i = 0; i < 109; i++)
                Console.Write("~");
            Console.Write(" ");
            for(int i = 0; i < 15; i += 3)
            {
              
                for (int j = 0; j < 3; j++)
                {
                    switch (j)
                    {
                        case 0:
                            Console.WriteLine("~ {0,0}: {1,-30}{2,0}: {3,-30}{4,0}: {5,-34}~",items.ElementAt(i).Location, items.ElementAt(i).Item,
                                items.ElementAt(i + 1).Location, items.ElementAt(i + 1).Item, items.ElementAt(i + 2).Location, items.ElementAt(i + 2).Item);
                            break;
                        case 1:
                            Console.WriteLine("~ Price: {0,-27:C}Price: {1,-27:C}Price{2,-33:C}~",
                                items.ElementAt(i).Price, items.ElementAt(i + 1).Price, items.ElementAt(i + 2).Price);
                            break;
                        case 2:
                            Console.WriteLine("~ Quantity Left: {0,-19}Quantity Left: {1,-19}Quantity Left: {2,-23}~",
                                items.ElementAt(i).Quantity, items.ElementAt(i + 1).Quantity, items.ElementAt(i + 2).Quantity);
                            Console.WriteLine("~{0,108}", "~");
                            break;
                        default:
                            Console.Write("I goofed up something");
                            break;
                    }
                }  
            }
            for (int i = 0; i < 109; i++)
                Console.Write("~");
            Console.Write(" ");
        }
        public static string makeChange(VendingItemClass item)
        {
            balance -= item.Price;
            double dollar = 0, quarter = 0, dime = 0, nickel = 0;
            while(balance >= 1)
            {
                balance -= 1;
                dollar++;
            }
            while(balance >= 0.25)
            {
                balance -= 0.25;
                quarter++;
            }
            while(balance >= 0.10)
            {
                balance -= 0.10;
                dime++;
            }
            while(balance > 0.04)
            {
                balance -= 0.05;
                nickel++;
            }
            string change = " Your change is " + dollar + " Dollars, " + quarter + " Quarters, " + dime + " Dimes, " + nickel + " Nickels.";
            balance = 0;
            return change;
        }
        public static void buyItem()
        {
            bool run = true;
            do
            {
              
                displayMachine();
                Console.Write(" Your balance is {0:C}. Please make your selection: ", balance);
                string selection = Console.ReadLine();
                foreach(VendingItemClass i in items)
                {
                    if(i.Location.ToUpper() == selection.ToUpper())
                    {
                        if(i.Price > balance)
                        {
                            Console.WriteLine(" Your selected item {0} costs more than your balance", i.Item);
                            Console.WriteLine(" Your money is returned. Press any key to continue");
                            Console.ReadKey();
                            balance = 0;
                            run = false;
                        }
                        else
                        {
                            displayMachine();
                            if(i.Quantity > 0)
                            {
                              
                                Console.WriteLine(" Dispensing {0}. ", i.Item);
                                Console.WriteLine(makeChange(i));
                                Console.WriteLine(" Press any key to continue.");
                                Console.ReadKey();
                                i.reduceInventory();
                                run = false;
                            }
                            else
                            {
                                Console.WriteLine(" Sorry that item is sold out: Press any key to try again:");
                                Console.ReadKey();
                            }
                        }
                    }
                }
              
            } while(run);

        }
    }
  
}


VendingItemClass.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace P04VendingMachine
{
    class VendingItemClass
    {
        private string item;
        private string location;
        private double price;
        private int quantity;
      
        public VendingItemClass(string _item, double _price, string _location, int _quantity)
        {
            item = _item;
            location = _location;
            price = _price;
            quantity = _quantity;
        }

        public string Item
        {
            get
            {
                return item;
            }

            set
            {
                item = value;
            }
        }

        public double Price
        {
            get
            {
                return price;
            }

            set
            {
                price = value;
            }
        }

        public string Location
        {
            get
            {
                return location;
            }

            set
            {
                location = value;
            }
        }

        public int Quantity
        {
            get
            {
                return quantity;
            }

            set
            {
                quantity = value;
            }
        }

        public void reduceInventory()
        {
            quantity--;
        }
    }
}