示例#1
0
        static void Main(string[] args)
        {
            Fruits Banana = new Fruits {
                ProductName = "Banana", ProductPrice = 5, ProductInfo = "A yellow 15 cm slightly curved fruit\t", ProductId = 1, HowToConsume = "You have to peel this fruit."
            };
            Fruits Apple = new Fruits {
                ProductName = "Golden Delisious", ProductPrice = 6, ProductInfo = "A yellov-green apple.\t\t\t", ProductId = 2, HowToConsume = "You have to wash this fruit before eating it."
            };
            Drinks Coffee = new Drinks {
                ProductName = "Black Coffee", ProductPrice = 19, ProductInfo = "Coffee made from medium roasted beans.\t", ProductId = 3, Temperature = 40, Volume = 2, VolumeSet = "dl", HowToConsume = "Beware! This product could be warm to the touch."
            };
            Drinks CokaCola = new Drinks {
                ProductName = "Coka Cola", ProductPrice = 14, ProductInfo = "Coka-cola from the Coka-Cola Company.\t", ProductId = 4, Temperature = 5, Volume = 2, VolumeSet = "dl", HowToConsume = "You need to uncork this bottle before drinking it."
            };
            Drinks Sprite = new Drinks {
                ProductName = "Sprite", ProductPrice = 16, ProductInfo = "Sprite from the Coka-Cola Company.\t", ProductId = 5, Temperature = 5, Volume = 2, VolumeSet = "dl", HowToConsume = "You need to uncork this bottle before drinking it."
            };
            Snacks Japp = new Snacks {
                ProductName = "Japp", ProductPrice = 7, ProductInfo = "Chocklate covered peanuts.\t\t", ProductId = 6, Weight = 200, WeightSet = "grams", HowToConsume = "You need to unwrap this chokolate bar before eating it."
            };
            Snacks Daim = new Snacks {
                ProductName = "Daim", ProductPrice = 8, ProductInfo = "Chocklate covered caramell.\t\t", ProductId = 7, Weight = 150, WeightSet = "grams", HowToConsume = "You need to unwrap this chokolate bar before eating it."
            };

            List <Products> allProducts = new List <Products>
            {
                Banana,
                Apple,
                Coffee,
                CokaCola,
                Sprite,
                Japp,
                Daim
            };

            BuyingBasket MyBasket           = new BuyingBasket();
            string       chosenProduct      = "";
            bool         exitVendingMachine = false;
            int          numberOfItemsToAdd = 0;
            int          valueOfBasket      = 0;
            int          totalAmountOfMoney = 0;
            int          change             = 0;
            int          menuChoise         = 0;

            do
            {
                Console.Clear();
                Console.WriteLine("Welcome to Vending Machines Inc! Have a drink and snack and be refreshed!");
                Console.WriteLine($"You have {totalAmountOfMoney} SEK to buy for.");
                Console.WriteLine($"You have items for a value of {valueOfBasket} SEK in your basket");
                Console.WriteLine("1. Insert money.");
                Console.WriteLine("2. List the available products.");
                Console.WriteLine("3. Examine a product.");
                Console.WriteLine("4. Show my basket.");
                Console.WriteLine("5. Add a product to basket.");
                Console.WriteLine("6. Cancel a purchase.");
                Console.WriteLine("7. Make a purchase.");
                Console.WriteLine("8. Exit the vending machine.");
                Console.Write($"Your choise is: ");
                menuChoise = 0;
                try
                {
                    menuChoise = (Convert.ToInt32(Console.ReadLine()));
                }
                catch (FormatException)
                {
                    Console.WriteLine("You typed a letter instead of a number. Try again.");
                }

                switch (menuChoise)
                {
                case 1:     //lets the user add money to the vending machine
                    totalAmountOfMoney = totalAmountOfMoney + AddMoney(totalAmountOfMoney);
                    break;

                case 2:     //lists the current items that can be bought.
                    Console.Clear();
                    Console.WriteLine("The following products is available in this vending machine.\nName\t\t\tDescription\t\t\t\tPrice");
                    Products.Examine(allProducts);
                    Console.WriteLine("Please hit any key to continue");
                    Console.ReadKey();
                    break;

                case 3:     //shows more detailed info about a product
                    do
                    {
                        Console.Clear();
                        Console.WriteLine("What product of the following would you like to take a closer look at? \nPlease type the name of the product.");
                        Products.Examine(allProducts);
                        Console.Write("What item would you like to look closer at: ");
                        try
                        {
                            chosenProduct = Console.ReadLine();
                        }
                        catch (FormatException)
                        {
                            Console.WriteLine("You have not typed in a correct name or amount. Please try again.");
                        }
                    } while (chosenProduct == "");
                    chosenProduct = ValidateChosenProduct(chosenProduct);
                    foreach (var element in allProducts)
                    {
                        if ((chosenProduct == element.ProductName) && (element is Drinks))
                        {
                            element.ShowProductSpecifics(chosenProduct, allProducts);
                        }
                        else if ((chosenProduct == element.ProductName) && (element is Fruits))
                        {
                            element.ShowProductSpecifics(chosenProduct, allProducts);
                        }
                        else if ((chosenProduct == element.ProductName) && (element is Snacks))
                        {
                            element.ShowProductSpecifics(chosenProduct, allProducts);
                        }
                    }
                    //Console.ReadKey();
                    break;

                case 4:    //shows the contents of the basket
                    valueOfBasket = MyBasket.ShowBasket(MyBasket.MyBasketContents);
                    break;

                case 5:     //lets the user add items to the basket.
                    do
                    {
                        Console.Clear();
                        Console.WriteLine("What product would you like to add to your buying basket? \nPlease type the name of the product.");
                        Products.Examine(allProducts);
                        Console.Write("What item would you like to add: ");
                        try
                        {
                            chosenProduct = Console.ReadLine();
                            Console.Write($"How many {chosenProduct} would you like to have? ");
                            numberOfItemsToAdd = Convert.ToInt32(Console.ReadLine());
                        }
                        catch (FormatException)
                        {
                            Console.WriteLine("You have not typed in a correct name or amount. Please try again.");
                        }
                    } while (chosenProduct == "");
                    chosenProduct = ValidateChosenProduct(chosenProduct);
                    MyBasket.MyBasketContents.Add(MyBasket.AddProductToBasket(chosenProduct, numberOfItemsToAdd, allProducts, MyBasket.MyBasketContents));
                    valueOfBasket = MyBasket.BasketValue(MyBasket.MyBasketContents);
                    break;

                case 6:
                    MyBasket.MyBasketContents.Clear();
                    valueOfBasket = 0;
                    MyBasket.Purchase(totalAmountOfMoney);
                    totalAmountOfMoney = 0;
                    break;

                case 7:    //let the user get the items so far chosen and subtracts the value of the items from the inserted money.
                    if (totalAmountOfMoney <= valueOfBasket)
                    {
                        Console.WriteLine("You have not inserted enough money!!");
                        Console.ReadKey();
                        break;
                    }
                    change             = totalAmountOfMoney - valueOfBasket;
                    totalAmountOfMoney = 0;
                    valueOfBasket      = 0;
                    //Console.ReadKey();
                    MyBasket.Purchase(change);
                    Products.Use(MyBasket.MyBasketContents, allProducts);
                    MyBasket.MyBasketContents.Clear();
                    break;

                case 8:     //exits the vending machine.
                    exitVendingMachine = true;
                    break;

                default:
                    Console.WriteLine("You typed in a choise the vending machine dont suppport, please make another choise.");
                    Console.ReadKey();
                    break;
                }
            } while (exitVendingMachine == false);
        }
示例#2
0
        //Adding Prdoucts to the inventory and Displaying them.
        public static void InitializeProducts()
        {
            Console.WriteLine("\n Drinks In the machine");
            Console.WriteLine("-----------------------");
            Drinks coke = new Drinks("Coco Cola", 1011, 10, "Refreshing Drink! Enjoy it cold");

            coke.Examine();
            drinkslist.Add(coke);

            Drinks fanta = new Drinks("Fanta Lime", 1012, 10, "Refreshing Drink! Enjoy it cold");

            fanta.Examine();
            drinkslist.Add(fanta);

            Drinks water = new Drinks("Vitamin Water", 1013, 24, "Energy Drink to increase your vitamins");

            water.Examine();
            drinkslist.Add(water);
            Console.WriteLine("*******************************");

            Console.WriteLine("\n Snacks In the machine");
            Console.WriteLine("-----------------------");
            Snacks pringles = new Snacks("Pringles", 1021, 9, "Classic Salt Flavoured Potato Chips");

            pringles.Examine();
            snackslist.Add(pringles);

            Snacks lays = new Snacks("Lays Classic", 1022, 20, "Cream and Onion Flavoured Potato Chips");

            lays.Examine();
            snackslist.Add(lays);

            Snacks cheez = new Snacks("Cheez Doodles", 1023, 13, "Cheese Flavoured Balls");

            cheez.Examine();
            snackslist.Add(cheez);

            Console.WriteLine("*******************************");
            Console.WriteLine("\n Food items In the machine");
            Console.WriteLine("-----------------------");
            Food mealbar = new Food("Nature diet Protien Meal bar", 1031, 26, "Diet protien bar with Crunchy chocolate ");

            mealbar.Examine();
            foodlist.Add(mealbar);

            Food tramezzino = new Food("Tramezzino - Tuna Sandwich", 1032, 40, "Tuna sandwich with green Olives, Can be used in Microwave");

            tramezzino.Examine();
            foodlist.Add(tramezzino);

            Food panini = new Food("Panini -Chicken Sandwich", 1033, 55, "Roasted Chicken sandwich with tomotoes, Can be used in Microwave");

            panini.Examine();
            foodlist.Add(panini);

            Console.WriteLine("*******************************");
            Console.WriteLine("\n Chocolates In the machine");
            Console.WriteLine("-----------------------");

            Chocolate snickers = new Chocolate("Snickers", 1041, 13, "Nutty Chocolate bar!");

            snickers.Examine();
            chocolatelist.Add(snickers);

            Chocolate bounty = new Chocolate("Bounty", 1042, 13, "Coconut  filled Chocolate bar!");

            bounty.Examine();
            chocolatelist.Add(bounty);

            Chocolate kex = new Chocolate("Kex Choco", 1043, 12, "Crunchy Wafer Chocolate!");

            kex.Examine();
            chocolatelist.Add(kex);
        }
示例#3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                Snack[] obj = new Snack[10];
                obj[0] = new Snack();
                obj[1] = new Snack();
                obj[2] = new Snack();
                obj[3] = new Snack();
                obj[4] = new Snack();
                obj[5] = new Snack();
                obj[6] = new Snack();
                obj[7] = new Snack();
                obj[8] = new Snack();
                obj[9] = new Snack();

                Drinks[] obej = new Drinks[10];
                obej[0] = new Drinks();
                obej[1] = new Drinks();
                obej[2] = new Drinks();
                obej[3] = new Drinks();
                obej[4] = new Drinks();
                obej[5] = new Drinks();
                obej[6] = new Drinks();
                obej[7] = new Drinks();
                obej[8] = new Drinks();
                obej[9] = new Drinks();

                Candy[] obbj = new Candy[10];
                obbj[0] = new Candy();
                obbj[1] = new Candy();
                obbj[2] = new Candy();
                obbj[3] = new Candy();
                obbj[4] = new Candy();
                obbj[5] = new Candy();
                obbj[6] = new Candy();
                obbj[7] = new Candy();
                obbj[8] = new Candy();
                obbj[9] = new Candy();

                obj[0].name      = "Lays";
                obj[0].price     = Convert.ToDecimal(.45);
                obj[0].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\lays-potato-chips-regular.jpg";
                obj[0].id        = "A1";
                obj[0].type      = "Chips";
                obj[0].inventory = 1;
                obj[1].name      = "Doritos";
                obj[1].price     = Convert.ToDecimal(.45);
                obj[1].id        = "A2";
                obj[1].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\doritos.jpg";
                obj[1].inventory = 16;
                obj[2].name      = "Snyders";
                obj[2].price     = Convert.ToDecimal(.45);
                obj[2].id        = "A3";
                obj[2].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\snyders.jpg";
                obj[2].inventory = 16;
                obj[3].name      = "Combos";
                obj[3].price     = Convert.ToDecimal(.45);
                obj[3].id        = "B4";
                obj[3].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\combos.jpg";
                obj[3].inventory = 16;

                obej[0].name      = "Pepsi";
                obej[0].price     = Convert.ToDecimal(.85);
                obej[0].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\pepsi.jpg";
                obej[0].id        = "B5";
                obej[0].type      = "Soda";
                obej[0].inventory = 16;
                obej[1].name      = "Coca Cola";
                obej[1].price     = Convert.ToDecimal(.85);
                obej[1].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\coke.jpg";
                obej[1].id        = "B6";
                obej[1].type      = "Soda";
                obej[1].inventory = 16;
                obej[2].name      = "Pepsi";
                obej[2].price     = Convert.ToDecimal(.85);
                obej[2].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\gatorade.jpg";
                obej[2].id        = "B7";
                obej[2].type      = "Juice";
                obej[2].inventory = 16;
                obej[3].name      = "Aquafina";
                obej[3].price     = Convert.ToDecimal(.85);
                obej[3].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\water.jpg";
                obej[3].id        = "C8";
                obej[3].type      = "Water";
                obej[3].inventory = 16;

                obbj[0].name      = "Swedish Fish";
                obbj[0].price     = Convert.ToDecimal(.95);
                obbj[0].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\fish.jpg";
                obbj[0].id        = "C9";
                obbj[0].type      = "Gummy";
                obbj[0].inventory = 16;
                obbj[1].name      = "Hershey";
                obbj[1].price     = Convert.ToDecimal(.95);
                obbj[1].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\hershey.png";
                obbj[1].id        = "C0";
                obbj[1].type      = "Chocoloate";
                obbj[1].inventory = 16;
                obbj[2].name      = "Skittles";
                obbj[2].price     = Convert.ToDecimal(.95);
                obbj[2].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\skittles.jpg";
                obbj[2].id        = "D1";
                obbj[2].type      = "Bite-Size";
                obbj[2].inventory = 16;
                obbj[3].name      = "Reese's";
                obbj[3].price     = Convert.ToDecimal(.85);
                obbj[3].img       = "C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\reeses.jpg";
                obbj[3].id        = "D2";
                obbj[3].type      = "Chocolate";
                obbj[3].inventory = 16;

                XmlSerializer serializer = new XmlSerializer(typeof(Snack[]));
                Stream        stream     = new FileStream
                                               ("Snacks.xml", FileMode.Create, FileAccess.Write, FileShare.None);
                serializer.Serialize(stream, obj);
                stream.Close();
                XmlSerializer serializer1 = new XmlSerializer(typeof(Drinks[]));
                Stream        stream1     = new FileStream
                                                ("Drinks.xml", FileMode.Create, FileAccess.Write, FileShare.None);
                serializer1.Serialize(stream1, obej);
                stream1.Close();
                XmlSerializer serializer2 = new XmlSerializer(typeof(Candy[]));
                Stream        stream2     = new FileStream
                                                ("Candy.xml", FileMode.Create, FileAccess.Write, FileShare.None);
                serializer2.Serialize(stream2, obbj);
                stream2.Close();


                vm = new Machine();

                for (int x = 0; x < vm.picArray.Length; x++)
                {
                    this.Controls.Add(vm.picArray[x]);
                    this.Controls.Add(vm.lblArray[x]);
                    this.Controls.Add(vm.lblArray[x]);
                    this.Controls.Add(vm.lblArray1[x]);
                    this.Controls.Add(vm.picArray1[x]);
                    this.Controls.Add(vm.lblArray2[x]);
                    this.Controls.Add(vm.picArray2[x]);
                }

                for (int x = 0; x < vm.btnArray.Length; x++)
                {
                    this.Controls.Add(vm.btnArray[x]);
                    this.Controls.Add(vm.btnArray1[x]);
                    this.Controls.Add(vm.btnArray2[x]);
                }
                Size FormSize = new Size(800, 600);
                this.Size      = (FormSize);
                this.BackColor = Color.FromArgb(26, 67, 207);
                Point pntQuarter = new Point(5, 350);
                Point pntDime    = new Point(70, 465);
                Point pntNickel  = new Point(110, 350);
                btnQuarter.BackgroundImage = Image.FromFile("C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\quarter.png");
                btnQuarter.Size            = new Size(100, 100);
                btnQuarter.Location        = pntQuarter;
                btnDime.Size            = new Size(70, 90);
                btnDime.BackgroundImage = Image.FromFile("C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\dime.jpg");
                btnDime.Location        = pntDime;
                //Nickel Button
                btnNickel.Location        = pntNickel;
                btnNickel.BackgroundImage = Image.FromFile("C:\\Users\\owner\\Documents\\School\\IST 240\\VendingMachine\\VendingMachine\\Pictures\\nickel.jpg");
                btnNickel.Size            = new Size(90, 100);
                btnNickel.Click          += coinClick;
                btnQuarter.Click         += coinClick;
                btnDime.Click            += coinClick;
                //Amount Deposited
                txtAmount.Location  = new Point(350, 450);
                txtAmount.ReadOnly  = true;
                txtAmount.ForeColor = Color.GreenYellow;
                txtAmount.BackColor = Color.Black;
                this.Controls.Add(btnQuarter);
                this.Controls.Add(btnDime);
                this.Controls.Add(btnNickel);
                this.Controls.Add(txtAmount);
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }