コード例 #1
0
ファイル: Menu.cs プロジェクト: azichbrad/VendingMachine
        public static void TakeMoneyMenu()
        {
            Console.WriteLine("-------This vending machine only accepts whole dollar amounts: $1, $2, $5, $10-------");
            Console.WriteLine();
            Console.WriteLine("Please select your amount:");
            Console.WriteLine("1) $1");
            Console.WriteLine("2) $2");
            Console.WriteLine("3) $5");
            Console.WriteLine("4) $10");

            Console.WriteLine();

            int moneySelectValue = 0;

            int.TryParse(Console.ReadLine(), out moneySelectValue);
            decimal addMoney = 0M;

            if (moneySelectValue > 0 && moneySelectValue <= 4)
            {
                addMoney = CashRegister.ShouldAddToBalance(moneySelectValue);

                AuditLog.createAuditEntry("FEED MONEY", CashRegister.previousBalance, CashRegister.balance);
                CashRegister.AddToBalance(addMoney);
            }
            else
            {
                Console.WriteLine("Invalid selection.");
                TakeMoneyMenu();
            }
            PurchaseMenu();
        }
コード例 #2
0
        public static void VendingItem(string slotID)
        {
            Console.WriteLine("Vending item...");
            CashRegister.previousBalance = CashRegister.balance;
            CashRegister.SubtractFromBalance(slot[slotID].slotItem[0].ItemCost);
            Console.WriteLine($"Item: {slot[slotID].slotItem[0].ItemName} Cost: {slot[slotID].slotItem[0].ItemCost:C2} Current Balance: {CashRegister.balance:C2}");

            Console.WriteLine(slot[slotID].slotItem[0].MakeSound());
            AuditLog.createAuditEntry(($"{slotID} {slot[slotID].slotItem[0].ItemName}"), CashRegister.balance, CashRegister.previousBalance);
            slot[slotID].slotItem.RemoveAt(0);
            Console.WriteLine();
            Console.WriteLine("Press any key to return to the Purchasing Menu.");
            Console.ReadKey();
            Menu.PurchaseMenu();
        }
コード例 #3
0
        public void ChangeCalculatorEndingBalance()
        {
            decimal balance = 0;

            CashRegister.ChangeWithLeastAmountOfCoins();

            Assert.AreEqual(0M, CashRegister.balance);

            balance = 10M;
            CashRegister.ChangeWithLeastAmountOfCoins();
            Assert.AreEqual(0M, CashRegister.balance);

            balance = 1500M;
            CashRegister.ChangeWithLeastAmountOfCoins();
            Assert.AreEqual(0M, CashRegister.balance);
        }
コード例 #4
0
        public void CorrectSelection()
        {
            decimal balance = 1;

            CashRegister.ShouldAddToBalance(1);
            Assert.AreEqual(1M, CashRegister.addMoney);

            balance = 2;
            CashRegister.ShouldAddToBalance(2);
            Assert.AreEqual(2M, CashRegister.addMoney);

            balance = 5;
            CashRegister.ShouldAddToBalance(3);
            Assert.AreEqual(5M, CashRegister.addMoney);

            balance = 10;
            CashRegister.ShouldAddToBalance(4);
            Assert.AreEqual(10M, CashRegister.addMoney);
        }
コード例 #5
0
ファイル: Menu.cs プロジェクト: azichbrad/VendingMachine
        public static void PurchaseMenu()
        {
            Console.Clear();
            Console.WriteLine("---- Purchasing Menu ----");
            Console.WriteLine("Please select a number 1 - 3 for the following menu options.");
            Console.WriteLine($"Current balance: {CashRegister.balance:C2}");
            Console.WriteLine();
            Console.WriteLine("(1) Feed Money");
            Console.WriteLine("(2) Select Product");
            Console.WriteLine("(3) Finish Transaction");
            string purchaseMenuSelect = Console.ReadLine();

            if (purchaseMenuSelect == "1")
            {
                Menu.TakeMoneyMenu();
                // unsure if we want to ask amounts here or elsewhere, if so will do another method to encompass that
            }
            else if (purchaseMenuSelect == "2")
            {
                VendingMachine.VendingSelection();
                // Show list of products available and Customer Enters a code to select.
                //if code doesnt exist return info and back to PurchaseMenu()
                //if sold out, informed then returned to PurchaseMenu()
                //if valid product selected it is dispensed:
            }
            else if (purchaseMenuSelect == "3")
            {
                CashRegister.ChangeWithLeastAmountOfCoins();
                AuditLog.UpdateAuditLog(VendingMachine.newAuditEntries);
                Console.ReadKey();
                //Customer finalizes all transactions and is returned to the MainMenu()
                //return change - using fewest coins using division and modulus probably
                //Machine current balance should be udpated to 0$ remaining
                //salesLog updated here or in option 2

                MainMenu();
            }
            else
            {
                Console.WriteLine("Not a valid menu selection");
                PurchaseMenu();
            }
        }
コード例 #6
0
        public void MoneySpent()
        {
            decimal cost = 3.05M;

            CashRegister.balance = 5M;
            CashRegister.SubtractFromBalance(cost);
            Assert.AreEqual(1.95M, CashRegister.balance);

            cost = 1M;
            CashRegister.balance = 10M;
            CashRegister.SubtractFromBalance(cost);
            Assert.AreEqual(9M, CashRegister.balance);

            cost = 5;
            CashRegister.balance = 5M;
            CashRegister.SubtractFromBalance(cost);
            Assert.AreEqual(0M, CashRegister.balance);

            cost = 1.5M;
            CashRegister.balance = 40M;
            CashRegister.SubtractFromBalance(cost);
            Assert.AreEqual(38.5M, CashRegister.balance);
        }
コード例 #7
0
        public void MoneyAccepted()
        {
            decimal balance = 10M;

            CashRegister.AddToBalance(10M);
            Assert.AreEqual(10M, CashRegister.balance);
            CashRegister.balance = 0M;

            balance = 5M;
            CashRegister.AddToBalance(5M);
            Assert.AreEqual(5M, CashRegister.balance);
            CashRegister.balance = 0M;

            balance = 2M;
            CashRegister.AddToBalance(2M);
            Assert.AreEqual(2M, CashRegister.balance);
            CashRegister.balance = 0M;

            balance = 1M;
            CashRegister.AddToBalance(1M);
            Assert.AreEqual(1M, CashRegister.balance);
            CashRegister.balance = 0M;
        }