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); }
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()); }
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); }