static void Main(string[] args) { CoinBox coinBox = new CoinBox(); CanRack vendingMachine = new CanRack(); PurchasePrice priceOfOneSoda = new PurchasePrice(0.35M); bool purchasingAnotherSoda = true; //List<Flavor> myHack = FlavorOps.AllFlavors; //myHack.Clear(); //WriteLine(FlavorOps.AllFlavors.ToString()); FlavorOps is wiped out!!!! if (args.Length > 0) { ProcessCommandLinePurchase(args, vendingMachine, priceOfOneSoda, coinBox); } while (purchasingAnotherSoda) { decimal totalAmountInserted = 0; decimal amountShort; WriteLine("Welcome to the .NET C# Soda Vending Machine"); WriteLine(vendingMachine.DisplayCanRack()); Write($"Please insert {priceOfOneSoda.Price} cents.\n"); Write("Enter your coins as one or more single letters separated by spaces, \n N(ickel), D(ime), Q(uarter), H(alfDollar): "); do { string userResponse = ReadLine(); coinBox = AddCoinsToCoinBoxFromListOfCoins(userResponse, coinBox); totalAmountInserted += AmountInsertedFromListOfCoins(userResponse); amountShort = priceOfOneSoda.PriceInDollars - totalAmountInserted; if (amountShort > 0) { Write($"Please insert at least {amountShort:C} more: "); } } while (totalAmountInserted < priceOfOneSoda.PriceInDollars); WriteLine($"You have inserted {totalAmountInserted:C}\n\n"); Flavor selectedFlavor = GetFlavorFromUser(vendingMachine); vendingMachine.RemoveACanOf(selectedFlavor); WriteLine($"Thanks. Here is your {selectedFlavor} soda."); if (amountShort < 0) { WriteLine($"and here is your change of {-amountShort:C}."); } WriteLine(vendingMachine.DisplayCanRack()); if (vendingMachine.IsEmpty()) { WriteLine("This vending machine is empty. Please visit your nearest Costco if you are still thirsty."); purchasingAnotherSoda = false; ReadKey(); } else { WriteLine("Press 'x' to exit or any other key to purchase another soda."); purchasingAnotherSoda = ReadKey().Key.ToString().ToLower() != "x"; } } WriteLine($"\nThe coin box contains \n{coinBox.ToString()}"); WriteLine($" and has a total value of {coinBox.ValueOf:C}."); WriteLine(" (ignores change returned) ToDo"); }
private static Flavor GetFlavorFromUser(CanRack vendingMachine) { bool selectionMade; Flavor selectedFlavor = Flavor.LEMON; do { WriteLine(vendingMachine.ConsoleInteractiveSelectionPrompt()); string userSelection = ReadLine(); try { selectedFlavor = FlavorOps.ToFlavor(userSelection?.ToUpper()); selectionMade = true; if (vendingMachine.IsEmpty(selectedFlavor)) { WriteLine($"Sorry, we are out of {selectedFlavor}, please make a different choice.\n"); selectionMade = false; } } catch (Exception badFlavorException) { WriteLine($"{badFlavorException.Message} Please try again...\n"); selectionMade = false; } } while (!selectionMade); return selectedFlavor; }
private static Flavor GetFlavorFromUser(CanRack vendingMachine) { bool selectionMade; Flavor selectedFlavor = Flavor.LEMON; do { WriteLine(vendingMachine.ConsoleInteractiveSelectionPrompt()); string userSelection = ReadLine(); try { selectedFlavor = FlavorOps.ToFlavor(userSelection?.ToUpper()); selectionMade = true; if (vendingMachine.IsEmpty(selectedFlavor)) { WriteLine($"Sorry, we are out of {selectedFlavor}, please make a different choice.\n"); selectionMade = false; } } catch (Exception badFlavorException) { WriteLine($"{badFlavorException.Message} Please try again...\n"); selectionMade = false; } } while (!selectionMade); return(selectedFlavor); }
static void Main(string[] args) { CoinBox coinBox = new CoinBox(); CanRack vendingMachine = new CanRack(); PurchasePrice priceOfOneSoda = new PurchasePrice(0.35M); bool purchasingAnotherSoda = true; //List<Flavor> myHack = FlavorOps.AllFlavors; //myHack.Clear(); //WriteLine(FlavorOps.AllFlavors.ToString()); FlavorOps is wiped out!!!! if (args.Length > 0) { ProcessCommandLinePurchase(args, vendingMachine, priceOfOneSoda, coinBox); } while (purchasingAnotherSoda) { decimal totalAmountInserted = 0; decimal amountShort; WriteLine("Welcome to the .NET C# Soda Vending Machine"); WriteLine(vendingMachine.DisplayCanRack()); Write($"Please insert {priceOfOneSoda.Price} cents.\n"); Write("Enter your coins as one or more single letters separated by spaces, \n N(ickel), D(ime), Q(uarter), H(alfDollar): "); do { string userResponse = ReadLine(); coinBox = AddCoinsToCoinBoxFromListOfCoins(userResponse, coinBox); totalAmountInserted += AmountInsertedFromListOfCoins(userResponse); amountShort = priceOfOneSoda.PriceInDollars - totalAmountInserted; if (amountShort > 0) { Write($"Please insert at least {amountShort:C} more: "); } } while (totalAmountInserted < priceOfOneSoda.PriceInDollars); WriteLine($"You have inserted {totalAmountInserted:C}\n\n"); Flavor selectedFlavor = GetFlavorFromUser(vendingMachine); vendingMachine.RemoveACanOf(selectedFlavor); WriteLine($"Thanks. Here is your {selectedFlavor} soda."); if (amountShort < 0) { WriteLine($"and here is your change of {-amountShort:C}."); } WriteLine(vendingMachine.DisplayCanRack()); if (vendingMachine.IsEmpty()) { WriteLine("This vending machine is empty. Please visit your nearest Costco if you are still thirsty."); purchasingAnotherSoda = false; ReadKey(); } else { WriteLine("Press 'x' to exit or any other key to purchase another soda."); purchasingAnotherSoda = ReadKey().Key.ToString().ToLower() != "x"; } } WriteLine($"\nThe coin box contains \n{coinBox.ToString()}"); WriteLine($" and has a total value of {coinBox.ValueOf:C}."); WriteLine(" (ignores change returned) ToDo"); }