public void Display(VendingMachine vend)
        {
            string directory = Environment.CurrentDirectory;
            string filename  = "Log.txt";
            string fullPath  = Path.Combine(directory, filename);

            vmfw = new VendingMachFileWriter(fullPath);

            List <Item> allPurchases = new List <Item>();

            while (true)
            {
                Console.WriteLine("(1) Feed Money");
                Console.WriteLine("(2) Select Product");
                Console.WriteLine("(3) Finish Transaction");
                Console.WriteLine("(Q) Return to Main Menu");

                string input = Console.ReadLine().ToUpper();

                if (input == "1" || input == "(1)")
                {
                    Console.WriteLine("Please enter a dollar amount(1, 2, 5, 10,)");
                    string[] validMoneyValues = { "1", "2", "5", "10" };
                    string   moneyInput       = Console.ReadLine();
                    if (validMoneyValues.Contains(moneyInput))
                    {
                        decimal moneyParsed = 0;

                        Decimal.TryParse(moneyInput, out moneyParsed);
                        vend.FeedMoney(moneyParsed);

                        Console.WriteLine("Money balance is " + vend.Balance.ToString("C"));
                        vmfw.LogMessage("FEED MONEY:     " + moneyParsed.ToString("C") + "      " + vend.Balance.ToString("C"));
                    }
                    else
                    {
                        Console.WriteLine("Amount not valid, your bill is being returned");
                    }
                }
                else if (input == "2" || input == "(2)")
                {
                    Console.WriteLine("Which slot would you like to choose?");

                    string slotInput = Console.ReadLine().ToUpper();
                    if (!vend.DoesSlotExist(slotInput))
                    {
                        Console.WriteLine("That slot does not exist, please try again");
                    }
                    else if (vend.IsSoldOut(slotInput))
                    {
                        Console.WriteLine("I'm sorry that item is sold out, please try again with another choice.");
                    }
                    else if (vend.InsufficientFunds(slotInput))
                    {
                        Console.WriteLine("I'm sorry you do not have enough money");
                    }
                    else
                    {
                        try
                        {
                            Item purchasedItem = vend.Purchase(slotInput);
                            allPurchases.Add(purchasedItem);

                            Console.WriteLine("you have purchased " + purchasedItem.Name);
                            Console.WriteLine("your new balance is " + vend.Balance);
                        }
                        catch (VendingMachineException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
                else if (input == "3" || input == "(3)")
                {
                    decimal oldBalance = vend.Balance;
                    Change  change     = vend.CompleteTransaction();
                    Console.WriteLine("Your Change is " + change.NumberOfQuarters + " quarters, " +
                                      change.NumberOfDimes + " dimes, " + change.NumberOfNickels + " nickles");

                    Console.WriteLine("Enjoy your meal!");
                    foreach (Item food in allPurchases)
                    {
                        Console.WriteLine(food.Consume());
                    }

                    vmfw.LogMessage("GIVE CHANGE :" + oldBalance.ToString("C") + "      " + vend.Balance.ToString("C"));

                    string salesPath = Path.Combine(directory, "salesreport.txt");
                    vmfw = new VendingMachFileWriter(salesPath);

                    decimal totalSales = 0;
                    foreach (Item item in allPurchases)
                    {
                        vmfw.SalesReport(item.Name + "|" + item.Price);
                        totalSales += item.Price;
                    }

                    vmfw.SalesReport("");
                    vmfw.SalesReport("**TOTAL SALES** " + totalSales.ToString("C"));
                    vmfw.SalesReport("");
                    vmfw.SalesReport("Never gonna give you up, never gonna let you down");
                    vmfw.SalesReport("Never gonna run around and desert you");
                    vmfw.SalesReport("Never gonna make you cry, never gonna say goodbye");
                    vmfw.SalesReport("Never gonna tell a lie and hurt you");
                }
                else if (input == "Q" || input == "(Q)")
                {
                    Console.WriteLine("Returning to Main Menu");
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public void Display()
        {
            PrintHeader();
            VendingMachine vendomatic = new VendingMachine();



            while (true)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Pick Yo Option");
                Console.WriteLine("1) Display Veding Machine items");
                Console.WriteLine("2) Purchase");
                string   input  = Console.ReadLine();
                string[] sloots = vendomatic.Slots;


                if (input == "1")
                {
                    for (int i = 0; i < sloots.Length; i++)
                    {
                        Console.WriteLine(sloots[i] + " " + vendomatic.GetQuantityRemaining(sloots[i]) + " " + vendomatic.GetItemAtSlot(sloots[i]).Name + " " + vendomatic.GetItemAtSlot(sloots[i]).Cost);
                    }
                }
                if (input == "2")
                {
                    while (true)
                    {
                        Console.WriteLine("Please Choose Below");
                        Console.WriteLine("1) Feed Money");
                        Console.WriteLine("2) Select Product");
                        Console.WriteLine("3) Finish Transaction");
                        string inputTwo = Console.ReadLine();
                        Console.WriteLine();
                        Console.WriteLine();
                        Console.WriteLine();

                        if (inputTwo == "1")
                        {
                            Console.WriteLine("Please enter amount in 1's, 5's, 10's or 20's");
                            string money = Console.ReadLine();
                            vendomatic.FeedMoney(int.Parse(money));
                            Console.WriteLine("Current balance is $" + vendomatic.CurrentBalance);
                        }
                        if (inputTwo == "2")
                        {
                            Console.WriteLine("Enter selected product code");
                            string userSelection = Console.ReadLine();
                            try
                            { for (int i = 0; i < sloots.Length - 1; i++)
                              {
                                  if (userSelection == sloots[i])
                                  {
                                      itemsBought.Add(vendomatic.Purchase(sloots[i]));
                                      Console.WriteLine("Here is your Item and current balance is " + vendomatic.CurrentBalance);
                                  }
                              }
                              //Console.WriteLine("Quantity remaining of selectd item is " + vendomatic.GetQuantityRemaining("slotID"));
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Sorry, your selection is invalid. Please try again");
                                Console.WriteLine(ex.Message);
                            }
                        }
                        if (inputTwo == "3")
                        {
                            Change coins = new Change(vendomatic.CurrentBalance);

                            for (int i = 0; i < itemsBought.Count; i++)
                            {
                                Console.WriteLine(itemsBought[i].Consume());
                            }
                            Console.WriteLine("Your money back is:");
                            Console.WriteLine("In Quarters " + coins.Quarters);
                            Console.WriteLine("In Dimes " + coins.Dimes);
                            Console.WriteLine("In Nickles " + coins.Nickels);
                            vendomatic.ReturnChange();
                            Console.WriteLine("Current Vendo Matic Balace is " + vendomatic.CurrentBalance);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void DisplayVendingMachine()
        {
            string userInput           = "";
            string purchaseInputOption = "";
            bool   isDone = false;

            while (isDone != true)
            {
                Console.WriteLine("\n(1) Display Vending Machine Items");
                Console.WriteLine("(2) Purchase");
                Console.WriteLine("(3) Quit");
                userInput = GetValidInput();

                if (userInput == "1")
                {
                    foreach (IVendingItem item in vendingMachine.Items)
                    {
                        //Console.WriteLine(item.ItemName + "|" + item.GetType());
                        string stockString = (item.Stock > 0) ? item.Stock.ToString() : "SOLD OUT";

                        Console.WriteLine(item.ItemSlot + ": " + item.ItemName + "..." + item.ItemPrice.ToString("c") + " Qty: " + stockString);
                    }
                }
                else if (userInput == "2")
                {
                    purchaseInputOption = DisplayPurchaseMenu();

                    while (purchaseInputOption != "3")
                    {
                        if (purchaseInputOption == "1")
                        {
                            PromptUserForMoney();
                        }
                        else if (purchaseInputOption == "2")
                        {
                            PromptForPurchase();
                        }
                        purchaseInputOption = DisplayPurchaseMenu();
                    }

                    if (purchaseInputOption == "3")
                    {
                        Change change = new Change();
                        change.ReturnChange((decimal)vendingMachine.CurrentMoneyProvided);

                        Console.WriteLine("You get back " + vendingMachine.CurrentMoneyProvided.ToString("C") + " in " + change.Quarters + " quarters, " + change.Dimes + " dimes, and " + change.Nickels + " nickels");

                        foreach (IVendingItem item in items)
                        {
                            Console.WriteLine(item.Message);
                        }


                        Transaction.PrintTransaction("GIVE CHANGE", vendingMachine.CurrentMoneyProvided, 0);
                    }
                }
                else if (userInput == "3")
                {
                    return;
                }
            }
        }