コード例 #1
0
        public void AddMoney(decimal cash) // adds cash to the balance
        {
            VendingWriter logWriter         = new VendingWriter();
            string        transactionString = " FEED MONEY:  $";

            transactionString += cash;

            balance = balance + cash;

            transactionString = transactionString + " $" + balance;
            logWriter.WritingAFile(transactionString);
        }
コード例 #2
0
        public string ReturnChange() // Return change sets the vending machine's balance field to 0, and returns a string
                                     // containing the coins they should receive back
        {
            VendingWriter vr = new VendingWriter();
            string        recordTransaction = ("GIVE CHANGE: $" + balance.ToString());

            Change coins = new Change(balance);

            balance = 0.00M;

            recordTransaction += " $0.00";
            vr.WritingAFile(recordTransaction);

            return(coins.ToString());
        }
コード例 #3
0
        public VendingItem BuyItem(string userSelection) // buys the item, reducing balance by the item's cost and
        {                                                // reducing the relevant inventory item by one.
            VendingItem product     = inventory[userSelection][0];
            decimal     productCost = product.Cost;

            if (balance >= productCost)
            {
                VendingWriter vr = new VendingWriter(); // writing to/formatting log
                string        recordTransaction = (inventory[userSelection][0].Name + " ");
                recordTransaction += userSelection + "  $" + balance + " ";
                balance           -= productCost;
                recordTransaction += "$" + balance; // more writing to the log
                vr.WritingAFile(recordTransaction);


                inventory[userSelection].RemoveAt(0);
                return(product);
            }
            return(null);
        }