Esempio n. 1
0
        private void SelectProduct()
        {
            Console.Clear();
            DisplayVendingMachineItems();
            Console.WriteLine("Please make selection.");
            string selection = Console.ReadLine().ToUpper();

            vendingMachine.SlotSelection = selection;
            string result = "";

            if (vendingMachine.IsSlotSelectionValid())
            {
                VendingMachineItem[] inventory = GetInventory();
                foreach (VendingMachineItem item in inventory)
                {
                    if (item.Slot == selection)
                    {
                        result = vendingMachine.DispenseItem(item);
                    }
                }
            }
            else
            {
                result = "Invalid selection entered.";
            }
            Console.WriteLine(result);
            Console.ReadLine();
        }
Esempio n. 2
0
        public void RunPurchase(VendingMachine VendoMatic600, string sLogPath)
        {
            Console.Write("Please Select Your Product by ID: ");
            bool   bIsValidProductNumber = false;
            bool   bIsValidProductLetter = false;
            string sInput = Console.ReadLine();

            bIsValidProductNumber = int.TryParse(sInput.Substring(1, 1), out int nNumber);
            bIsValidProductLetter = sInput.Substring(0, 1).ToUpper() == "A" ||
                                    sInput.Substring(0, 1).ToUpper() == "B" ||
                                    sInput.Substring(0, 1).ToUpper() == "C" ||
                                    sInput.Substring(0, 1).ToUpper() == "D";

            while (!bIsValidProductNumber || !bIsValidProductLetter || nNumber < 1 || nNumber > 4)
            {
                Console.WriteLine("Please enter a valid Product ID...   Format : LetterNumber");
                sInput = Console.ReadLine();
                bIsValidProductNumber = int.TryParse(sInput.Substring(1, 1), out nNumber);
                bIsValidProductLetter = sInput.Substring(0, 1).ToUpper() == "A" ||
                                        sInput.Substring(0, 1).ToUpper() == "B" ||
                                        sInput.Substring(0, 1).ToUpper() == "C" ||
                                        sInput.Substring(0, 1).ToUpper() == "D";
            }
            sInput = sInput.Substring(0, 1).ToUpper() + sInput.Substring(1, 1);

            if (VendoMatic600.GetSnackItems()[sInput].nAmount > 0)
            {
                VendoMatic600.Balance -= VendoMatic600.GetSnackItems()[sInput].dPrice;
                VendoMatic600.DecrementAmountOfSnack(VendoMatic600.GetSnackItems()[sInput], 1);
                Console.WriteLine(VendoMatic600.DispenseItem(VendoMatic600.GetSnackItems()[sInput]));
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("We Don't Have Any More, Go Away.");
            }
            using (StreamWriter newSW = new StreamWriter(sLogPath, true))
            {
                //write Date & Time
                newSW.Write(DateTime.Now.ToString() + " ");
                //write amount entered
                newSW.Write(VendoMatic600.GetSnackItems()[sInput].sName + " ");
                newSW.Write(VendoMatic600.GetSnackItems()[sInput].sLocation + " ");
                newSW.Write("$" + string.Format("{0:0.00}", VendoMatic600.GetSnackItems()[sInput].dPrice) + " ");
                //write balance
                newSW.Write($"${string.Format("{0:0.00}", VendoMatic600.Balance)}\n");
            }
        }
Esempio n. 3
0
        // Method Purchase Screen
        public void PurchaseSubmenu()
        {
            while (true)
            {
                Console.WriteLine($"Current Balance: {vendingMachine.Balance:C}");
                Console.WriteLine();
                Console.WriteLine("1. Feed Money");
                Console.WriteLine("2. Select Product");
                Console.WriteLine("3. Finish Transaction");

                Console.Write("Please make a selection: ");
                string input = Console.ReadLine();

                if (input == "1")
                {
                    Console.WriteLine();
                    Console.Write("Enter dollar amount to feed into the vending machine: ");

                    if (int.TryParse(Console.ReadLine(), out int dollarsEntered))
                    {
                        // Accepted dollar bills
                        if ((dollarsEntered == 1) || (dollarsEntered == 2) || (dollarsEntered == 5) || (dollarsEntered == 10))
                        {
                            Console.WriteLine();
                            vendingMachine.FeedMoney(dollarsEntered);
                        }
                        // Not an accepted bill amount
                        else
                        {
                            Console.WriteLine();
                            Console.WriteLine($"The dollar amount you have entered is not valid.");
                        }
                    }
                    // User tried to enter something other than integer
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine($"The dollar amount you have entered is not valid.");
                    }
                }
                else if (input == "2")
                {
                    Console.WriteLine();
                    DisplayInventory();
                    Console.Write("Enter the item position to purchase: ");
                    string possiblePurchase = Console.ReadLine().ToUpper();
                    Console.WriteLine();
                    vendingMachine.DispenseItem(possiblePurchase);
                }
                else if (input == "3")
                {
                    Console.WriteLine();
                    Console.Write("Here is your change: ");
                    Change change = vendingMachine.GiveChange();
                    Console.WriteLine($"{change.NumberOfQuarters} quarters, {change.NumberOfDimes} dimes, {change.NumberOfNickels} nickles");
                    Console.WriteLine();

                    while (vendingMachine.PurchasedItems.Count != 0)
                    {
                        //Console.WriteLine($"{vendingMachine.PurchasedItems[0].MakeSound()}");
                        //vendingMachine.PurchasedItems.RemoveAt(0);
                        Console.WriteLine($"{vendingMachine.ConsumeItems()}");
                    }

                    Console.ReadLine();
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter a valid selection!");
                }
            }
        }
Esempio n. 4
0
        public void PurchaseItem(VendingMachine vm)
        {
            string folder = "Logs";
            string path   = Environment.CurrentDirectory;

            Directory.CreateDirectory(folder);
            path = Path.Combine(path, folder, "Logs.txt");

            while (true)
            {
                string[] validInputs = new string[3] {
                    "1", "2", "3"
                };
                string input = "";
                while (!validInputs.Contains(input))
                {
                    Console.Clear();
                    Console.WriteLine("Choose one of the following:  ");
                    Console.WriteLine("1. Feed Money");
                    Console.WriteLine("2. Select Product");
                    Console.WriteLine("3. Finish Transaction");


                    if (vm.tenderAmount != 0)
                    {
                        Console.WriteLine($"Current Tender: {vm.tenderAmount:C2}");
                    }

                    input = Console.ReadLine();
                }

                if (input == "1")
                {
                    try
                    {
                        Console.Clear();
                        Console.WriteLine("Please insert tender (accepts $1, $2, $5, and $10) :");
                        decimal tender = decimal.Parse(Console.ReadLine());

                        if (!vm.ValidateTender(tender))
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        vm.InsertTender(path, tender);
                        input = "";
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Invalid tender amount, returning to menu.");
                        input = "";
                        Thread.Sleep(2000);
                    }
                }
                else if (input == "2")
                {
                    while (true)
                    {
                        vm.DisplayStock(vm);
                        Console.WriteLine("What would you like to purchase? ");
                        string nomNom = Console.ReadLine().ToUpper();
                        vm.DispenseItem(path, nomNom);

                        Console.WriteLine();

                        Console.Write("Press any key to return to the purchase menu:");
                        Console.ReadKey();
                        break;
                    }
                }
                else if (input == "3")
                {
                    Console.WriteLine(vm.DispenseChange(path));
                    Console.WriteLine("Press any key to return to the main menu.");
                    Console.ReadKey();
                    Console.Clear();
                    return;
                }
            }
        }
Esempio n. 5
0
        public void RunVendingMachine()
        {
            Vendomatic500.VendomaticAscii();

            int  selectedChoice   = 0;
            bool validAnswer      = false;
            bool returnToMainMenu = true;

            while (returnToMainMenu)
            {
                Console.WriteLine("MAIN MENU");
                Console.WriteLine("Please select from the following:");
                Console.WriteLine("1. Display Vending Machine Items \n2. Purchase \n3. Turn Off Vending Machine");
                Console.WriteLine();

                while (!validAnswer)
                {
                    try
                    {
                        selectedChoice = int.Parse(Console.ReadLine());

                        if (selectedChoice == 1 || selectedChoice == 2 || selectedChoice == 3)
                        {
                            validAnswer = true;;
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }

                    catch (Exception)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Please make a valid selection: 1, 2 or 3.");
                        Console.WriteLine("1. Display Vending Machine Items \n2. Purchase \n3. Turn Off Vending Machine");
                        Console.WriteLine();
                    }
                }

                if (selectedChoice == 1)
                {
                    Console.WriteLine();
                    Console.WriteLine(vm.DisplayItems());
                    Console.WriteLine("Press any button to return to the Main Menu.");
                    Console.ReadLine();
                    Console.WriteLine();
                    validAnswer = false;
                }

                else if (selectedChoice == 2)
                {
                    returnToMainMenu = false;
                    bool returnToPurchaseMenu = true;

                    while (returnToPurchaseMenu)
                    {
                        Console.WriteLine();
                        Console.WriteLine("PURCHASE MENU");
                        Console.WriteLine("Please select from the following:");
                        Console.WriteLine("1. Feed Money \n2. Select Product \n3. Complete Transaction");
                        Console.WriteLine("Your current available balance is " + vm.Balance + ".");
                        Console.WriteLine();
                        validAnswer = false;

                        while (!validAnswer)
                        {
                            try
                            {
                                selectedChoice = int.Parse(Console.ReadLine());

                                if (selectedChoice == 1 || selectedChoice == 2 || selectedChoice == 3)
                                {
                                    validAnswer          = true;
                                    returnToPurchaseMenu = false;
                                }
                                else
                                {
                                    throw new Exception();
                                }
                            }

                            catch (Exception)
                            {
                                Console.WriteLine();
                                Console.WriteLine("Please make a valid selection: 1, 2 or 3.");
                                Console.WriteLine("1. Feed Money \n2. Select Product \n3. Complete Transaction");
                                Console.WriteLine();
                            }
                        }

                        if (selectedChoice == 1)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Please insert a $1, $2, $5, or $10 bill.");
                            Console.WriteLine("To add $1: select 1. \nTo add $2: select 2. \nTo add $5: select 5. \nTo add $10: select 10.");
                            Console.WriteLine();

                            int paymentAmount = 0;
                            validAnswer = false;

                            while (!validAnswer)
                            {
                                try
                                {
                                    paymentAmount = int.Parse(Console.ReadLine());

                                    if (paymentAmount == 1 || paymentAmount == 2 || paymentAmount == 5 || paymentAmount == 10)
                                    {
                                        validAnswer          = true;
                                        returnToPurchaseMenu = false;
                                    }
                                    else
                                    {
                                        throw new Exception();
                                    }
                                }

                                catch (Exception)
                                {
                                    Console.WriteLine();
                                    Console.WriteLine("Please make a valid selection: 1, 2, 5, or 10.");
                                    Console.WriteLine();
                                }
                            }

                            vm.AddMoneyToBalance(paymentAmount);
                            vm.FeedMoneyToVMLog(paymentAmount);
                            returnToPurchaseMenu = true;
                        }

                        else if (selectedChoice == 2)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Please enter product code.");
                            Console.WriteLine();
                            string slotNumber = " ";

                            validAnswer = false;

                            while (!validAnswer)
                            {
                                try
                                {
                                    slotNumber = Console.ReadLine().ToUpper();

                                    if (vm.VMContents.ContainsKey(slotNumber))
                                    {
                                        validAnswer          = true;
                                        returnToPurchaseMenu = false;
                                    }

                                    else
                                    {
                                        throw new Exception();
                                    }
                                }

                                catch (Exception)
                                {
                                    Console.WriteLine();
                                    Console.WriteLine("You have entered a non-existant product code. Returning to Purchase Menu.");
                                    Console.WriteLine("To view item list, complete transaction and return to Main Menu.");
                                    validAnswer          = true;
                                    returnToPurchaseMenu = true;
                                }
                            }

                            while (!returnToPurchaseMenu)
                            {
                                if (vm.VMContents[slotNumber].Quantity > 0)
                                {
                                    vm.DispenseItem(slotNumber);

                                    if (vm.Balance.IsNegative)
                                    {
                                        vm.Balance = vm.Balance.Plus(vm.VMContents[slotNumber].Price);
                                        vm.VMContents[slotNumber].Quantity += 1;
                                        Console.WriteLine();
                                        Console.WriteLine("Your current balance is too low to make this purchase. Please add more money or select a different product.");
                                        returnToPurchaseMenu = true;
                                    }

                                    else
                                    {
                                        Console.WriteLine();
                                        Console.WriteLine(vm.VMContents[slotNumber].ToString());
                                        returnToPurchaseMenu = true;
                                        vm.ItemDispensedToLog(slotNumber);
                                    }
                                }

                                else
                                {
                                    Console.WriteLine();
                                    Console.WriteLine($"{vm.DispenseItem(slotNumber)}");
                                    Console.WriteLine("Returning to Purchase Menu.");
                                    returnToPurchaseMenu = true;
                                }
                            }
                        }

                        else if (selectedChoice == 3)
                        {
                            Console.WriteLine();
                            vm.ChangeDispensedToLog();
                            Console.WriteLine(vm.DispenseChange());
                            Console.WriteLine();
                            Console.WriteLine("Returning to main menu.");
                            Console.WriteLine();
                            returnToMainMenu = true;
                            validAnswer      = false;
                        }
                    }
                }

                else if (selectedChoice == 3)
                {
                    vm.SalesReport();
                    Environment.Exit(0);
                }
            }
        }
        public void PurchaseMenu()
        {
            Console.WriteLine();
            Console.WriteLine("(1) Feed Money");
            Console.WriteLine("(2) Select Product");
            Console.WriteLine("(3) Finish Transaction");


            int purchaseMenuChoice = int.Parse(Console.ReadLine());

            if (purchaseMenuChoice == 1)
            {
                Console.WriteLine();
                Console.Write("Please Insert Cash ($1, $2, $5, $10): $");
                try
                {
                    int inputMoney = int.Parse(Console.ReadLine());
                    if (inputMoney < 0)
                    {
                        Console.WriteLine("Balance Cannot Be Below $0.00"); // added if statement here to keep user from inputing negative money
                    }
                    else
                    {
                        vendingMachine.FeedMoney(inputMoney);
                        Console.WriteLine();
                        Console.WriteLine("Current Balance: $" + vendingMachine.CheckBalance());//changed to check balance because of bug with totalMoney variable
                        PurchaseMenu();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine();
                    Console.WriteLine("**********************************");
                    Console.WriteLine("Please Enter Whole Dollar Amount.");
                    Console.WriteLine("**********************************");
                    PurchaseMenu();
                }
            }
            if (purchaseMenuChoice == 2)
            {
                Console.WriteLine();
                Console.Write("Please Select Product: ");


                string inputProduct = Console.ReadLine();
                inputProduct = inputProduct.ToUpper(); //allows user input to be case insensitive
                int  balance     = vendingMachine.VendingBalance;
                bool doesExist   = vendingMachine.DoesExist(inputProduct);
                bool isAvailable = vendingMachine.IsAvailable(inputProduct);//changed these to be in variables to make it cleaner
                bool isEnough    = vendingMachine.IsEnoughMoney(inputProduct, balance);

                if (doesExist && isAvailable && isEnough)
                {
                    Console.WriteLine();
                    Console.WriteLine("-----------------------------------------");
                    Console.WriteLine(vendingMachine.DispenseItem(inputProduct));
                    Console.WriteLine("-----------------------------------------");
                    Console.WriteLine("Remaining Balance: $" + vendingMachine.CheckBalance());
                    Console.WriteLine();
                }
                else if (!doesExist)
                {
                    Console.WriteLine();
                    Console.WriteLine("Sorry That Item Doesn't Exist");
                }
                else if (!isAvailable)
                {
                    Console.WriteLine();
                    Console.WriteLine("Sorry That Item Is Out of Stock. Please Select Another Item");
                }
                else if (!isEnough)
                {
                    Console.WriteLine();
                    Console.WriteLine("Insuffienct Funds. Please Insert More $");
                }

                PurchaseMenu();
            }
            if (purchaseMenuChoice == 3)
            {
                Console.WriteLine();
                Console.WriteLine($"Your Change Is: $" + vendingMachine.CheckBalance());
                int[] changeArray = vendingMachine.GiveChange();

                Console.WriteLine("_________________________________");
                System.Threading.Thread.Sleep(3000);
                RunInterface();
            }
            else
            {
                PurchaseMenu();
            }
        }