Beispiel #1
0
 public void AddSnack(Snack snack, int n)
 {
     if (_stock.ContainsKey(snack.Code))
     {
         _stock[snack.Code] += n;
     }
     else
     {
         _assortment.Add(snack);
         _stock.Add(snack.Code, n);
     }
 }
Beispiel #2
0
 public Item[] FillMachineWithProducts()
 {
     Item[] newItems = new Item[9];
     newItems[0] = new Food("Big Mac", 79, 11, "A burger from McDonalds!");
     newItems[1] = new Food("Hawaii", 85, 12, "The pizza with pineapple!");
     newItems[2] = new Food("Kebab salad", 87, 13, "Kebab is it!");
     newItems[3] = new Drink("Red Bull", 28, 21, "Makes you fly!");
     newItems[4] = new Drink("Fanta", 22, 22, "Fantastic!");
     newItems[5] = new Drink("Beer", 49, 23, "Probably the best in the world!");
     newItems[6] = new Snack("Snickers", 14, 31, "Have a break!");
     newItems[7] = new Snack("Twix", 15, 32, "Twix it!");
     newItems[8] = new Snack("Protein Bar", 20, 33, "Makes you stronger!");
     return(newItems);
 }
Beispiel #3
0
        static List <Item> addItem(List <Item> currentInventory, int choice)
        {
            List <Item> listToReturn = currentInventory;

            if (choice == 1)
            {
                Console.WriteLine("Name of product to add: ");
                string nameToAdd   = Console.ReadLine();
                Item   nameToCheck = checkItemIsInMachine(nameToAdd, listToReturn);

                if (nameToCheck == null)
                {
                    //info needed for dispensing and invnetory management
                    Console.WriteLine("Category of product to add: ");
                    string categoryToAdd = Console.ReadLine();

                    Console.WriteLine("Price of product to add: ");
                    float priceToAdd = float.Parse(Console.ReadLine());

                    Console.WriteLine("Weight(g) of product to add: ");
                    int weightToAdd = int.Parse(Console.ReadLine());

                    Console.WriteLine("How many are you putting in the machine to start with?");
                    int quantityToAdd = int.Parse(Console.ReadLine());


                    //info needed for nutritional information
                    string perString;
                    float  calories, fat, carbohydrates, fibre, protein, salt;
                    Console.WriteLine("Per portion statement: ");
                    perString = Console.ReadLine();

                    Console.WriteLine("How many calories are in this item? ");
                    calories = float.Parse(Console.ReadLine());

                    Console.WriteLine("How much fat is in the Item? ");
                    fat = float.Parse(Console.ReadLine());

                    Console.WriteLine("How many carbohydrates are there in this item?");
                    carbohydrates = float.Parse(Console.ReadLine());

                    Console.WriteLine("how much fibre is in this item? ");
                    fibre = float.Parse(Console.ReadLine());

                    Console.WriteLine("How much protein is in this item? ");
                    protein = float.Parse(Console.ReadLine());

                    Console.WriteLine("finally, how much salt is in the item? ");
                    salt = float.Parse(Console.ReadLine());

                    Snack itemToAdd = new Snack(nameToAdd, categoryToAdd, priceToAdd, weightToAdd, quantityToAdd, perString, calories, fat, carbohydrates, fibre, protein, salt);
                    listToReturn.Add(itemToAdd);
                    return(listToReturn);
                }
                else
                {
                    Console.WriteLine("Item is already in the machine. Would you like to add more of it?");
                    Console.WriteLine("1 - yes");
                    Console.WriteLine("2 - no");
                    int tempChoice = int.Parse(Console.ReadLine());
                    if (tempChoice == 1)
                    {
                        Console.WriteLine("How many would you like to add? There are currently " + nameToCheck.GetQuantity() + " of this item in the machine.");
                        int quantityToAdd = int.Parse(Console.ReadLine());

                        for (int i = 0; i < listToReturn.Count(); i++)
                        {
                            if (listToReturn[i].GetName() == nameToCheck.GetName())
                            {
                                listToReturn[i].SetQuantity(listToReturn[i].GetQuantity() + quantityToAdd);
                            }
                        }
                        return(listToReturn);
                    }
                    return(listToReturn);
                }
            }
            else if (choice == 2)
            {
                Console.WriteLine("Name of product to add: ");
                string nameToAdd   = Console.ReadLine();
                Item   nameToCheck = checkItemIsInMachine(nameToAdd, listToReturn);

                if (nameToCheck == null)
                {
                    //info needed for dispensing and inventory management
                    Console.WriteLine("Category of product to add: ");
                    string categoryToAdd = Console.ReadLine();
                    Console.WriteLine("Price of product to add: ");
                    float priceToAdd = float.Parse(Console.ReadLine());
                    Console.WriteLine("capacity(ml) of product to add: ");
                    int capacityToAdd = int.Parse(Console.ReadLine());
                    Console.WriteLine("How many are you putting in the machine to start with?");
                    int quantityToAdd = int.Parse(Console.ReadLine());

                    //info needed for nutritional info
                    string perString;
                    float  calories, fat, carbohydrates, fibre, protein, salt;
                    Console.WriteLine("Per portion statement: ");
                    perString = Console.ReadLine();

                    Console.WriteLine("How many calories are in this item? ");
                    calories = float.Parse(Console.ReadLine());

                    Console.WriteLine("How much fat is in the Item? ");
                    fat = float.Parse(Console.ReadLine());

                    Console.WriteLine("How many carbohydrates are there in this item?");
                    carbohydrates = float.Parse(Console.ReadLine());

                    Console.WriteLine("how much fibre is in this item? ");
                    fibre = float.Parse(Console.ReadLine());

                    Console.WriteLine("How much protein is in this item? ");
                    protein = float.Parse(Console.ReadLine());

                    Console.WriteLine("finally, how much salt is in the item? ");
                    salt = float.Parse(Console.ReadLine());

                    Drink itemToAdd = new Drink(nameToAdd, categoryToAdd, priceToAdd, capacityToAdd, quantityToAdd, perString, calories, fat, carbohydrates, fibre, protein, salt);
                    listToReturn.Add(itemToAdd);
                    return(listToReturn);
                }
                else
                {
                    Console.WriteLine("Item is already in the machine. Would you like to add more of it?");
                    Console.WriteLine("1 - yes");
                    Console.WriteLine("2 - no");
                    int tempChoice = int.Parse(Console.ReadLine());
                    if (tempChoice == 1)
                    {
                        Console.WriteLine("How many would you like to add? There are currently " + nameToCheck.GetQuantity() + " of this item in the machine.");
                        int quantityToAdd = int.Parse(Console.ReadLine());

                        for (int i = 0; i < listToReturn.Count(); i++)
                        {
                            if (listToReturn[i].GetName() == nameToCheck.GetName())
                            {
                                listToReturn[i].SetQuantity(listToReturn[i].GetQuantity() + quantityToAdd);
                            }
                        }
                        return(listToReturn);
                    }
                    return(listToReturn);
                }
            }
            else
            {
                //incompatible input
                return(currentInventory);
            }
        }
Beispiel #4
0
 public Snack(Snack Snack) :
     base(Snack)
 {
 }
Beispiel #5
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());
            }
        }