コード例 #1
0
        /// <summary>
        /// takes user input and increments the MachineBalance
        /// by the number of dollars per bill "fed"
        /// also sets property values for LogColA and LogColB
        /// to be written in the log
        /// finally, prints appropriate info to the log
        /// </summary>
        /// <param name="input"></param>
        public void FeedMoney(char input)
        {
            if (input == '1')
            {
                MachineBalance += 1;
                LogColA         = "$1.00";
            }
            else if (input == '2')
            {
                MachineBalance += 2;
                LogColA         = "$2.00";
            }
            else if (input == '3')
            {
                MachineBalance += 5;
                LogColA         = "$5.00";
            }
            else if (input == '4')
            {
                MachineBalance += 10;
                LogColA         = "$10.00";
            }
            else if (input == '5')
            {
                MachineBalance += 20;
                LogColA         = "$20.00";
            }

            LogColB = MachineBalance.ToString("C");
            Event   = "FEED MONEY:";

            PrintToLog();
        }
コード例 #2
0
        /// <summary>
        /// calculates change by dividing the MachineBalance
        /// into quarters, then dimes, then nickels
        /// updates appropriate log properties and writes to log
        /// </summary>
        /// <returns>string displaying what coins user received after transaction</returns>
        public string FinishTransaction()
        {
            int balance = (int)(MachineBalance * 100);

            int nickel  = 5;
            int dime    = 10;
            int quarter = 25;

            int nickelCount  = 0;
            int dimeCount    = 0;
            int quarterCount = 0;

            LogColA = MachineBalance.ToString("C");

            while (balance > 0)
            {
                if (balance >= quarter)
                {
                    balance -= quarter;
                    quarterCount++;
                }
                else if (balance >= dime)
                {
                    balance -= dime;
                    dimeCount++;
                }
                else if (balance >= nickel)
                {
                    balance -= nickel;
                    nickelCount++;
                }
            }

            string change = $"Your change is {nickelCount} nickels, " +
                            $"{dimeCount} dimes, and {quarterCount} quarters.";

            MachineBalance = 0;
            LogColB        = 0.ToString("C");
            Event          = "GIVE CHANGE:";

            PrintToLog();
            GenerateSalesReport();

            return(change);
        }
コード例 #3
0
        /// <summary>
        /// updates the MachineBalance by finding the Item
        /// matching the slot ID entered and subtracts the item's
        /// price from the MachineBalance
        /// also updates TotalSales by adding the item price
        /// to TotalSales
        /// also updates property values for the appropriate log
        /// Event, LogColA, and LogColB
        /// finally, prints to log
        /// </summary>
        /// <param name="slot">slot ID entered by user</param>
        public void UpdateBalance(string slot)
        {
            foreach (Item item in _itemList)
            {
                bool selectionMatch = item.Slot.ToLower() == slot.ToLower();

                if (selectionMatch)
                {
                    Event   = $"{item.Name} {item.Slot}";
                    LogColA = MachineBalance.ToString("C");

                    MachineBalance -= item.Price;
                    TotalSales     += item.Price;

                    LogColB = MachineBalance.ToString("C");

                    PrintToLog();
                }
            }
        }