// Customer can call this to check what is in the wallet public void CoinsInWallet() { UserInterface.SeparatorLine(); UserInterface.OutputText($"You have ${Coin.TotalCoinValue(Coins):F2} in coins"); UserInterface.DisplayObjects(Coins); UserInterface.SeparatorLine(); }
private void DisplayStatus() { UserInterface.SeparatorLine(); UserInterface.OutputText($"The Soda Machine has made a total of ${bankAccount:F2} from credit card sales"); UserInterface.OutputText("The Soda Machine has these in stock:"); UserInterface.DisplayObjects(_inventory); UserInterface.OutputText($"The Soda Machine has ${Coin.TotalCoinValue(_register):F2} in change"); UserInterface.DisplayObjects(_register); UserInterface.SeparatorLine(); }
//This is the main method for calculating the result of the transaction. //It takes in the payment from the customer, the soda object they selected, and the customer who is purchasing the soda. //This is the method that will determine the following: //If the payment is greater than the price of the soda, and if the sodamachine has enough change to return: Despense soda, and change to the customer. //If the payment is greater than the cost of the soda, but the machine does not have ample change: Despense payment back to the customer. //If the payment is exact to the cost of the soda: Despense soda. //If the payment does not meet the cost of the soda: despense payment back to the customer. private void CalculateTransaction(List <Coin> payment, Can chosenSoda, Customer customer) { double totalAmount = Coin.TotalCoinValue(payment); // Need to give back extra // Because of Double inaccuraies, it would be easiest to check for equals first // if Equal if (Math.Abs(totalAmount - chosenSoda.Price) < doubleErrorMargin) { UserInterface.EndMessage(chosenSoda.Name, 0); customer.AddCanToBackpack(chosenSoda); DepositCoinsIntoRegister(payment); } // If the value + error margin that could make it go slightly below is greater than Soda price else if (totalAmount + doubleErrorMargin > chosenSoda.Price) { // Check to see if machine has enough change double change = DetermineChange(Coin.TotalCoinValue(payment), chosenSoda.Price); List <Coin> changeInCoins = GatherChange(change); if (changeInCoins is null) { UserInterface.OutputText($"The soda machine does not have enough change, returning ${Coin.TotalCoinValue(payment):F2}"); // Return money and put soda back customer.AddCoinsIntoWallet(payment); _inventory.Add(chosenSoda); } else { UserInterface.EndMessage(chosenSoda.Name, Coin.TotalCoinValue(changeInCoins)); customer.AddCanToBackpack(chosenSoda); DepositCoinsIntoRegister(payment); customer.AddCoinsIntoWallet(changeInCoins); } } else // Has to be less than { // Give back the money, and put soda back into inventory UserInterface.OutputText("Not enough for soda, returning money"); customer.AddCoinsIntoWallet(payment); _inventory.Add(chosenSoda); } DisplayStatus(); }