Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Debug.WriteLine("This goes to the debug window");
            Debug.WriteLine("To make this window visible use menu item");
            Debug.WriteLine("Debug\\Windows\\Output");

            //Create a purchase price object
            PurchasePrice currentPrice = new PurchasePrice();

            //Create a CanRack object
            CanRack canRack = new CanRack();

            while (true)
            {
                //Introduce the program
                Console.WriteLine("Welcome to the .NET C# Soda Vending Machine");

                //Prompt the user for input
                Console.Write($"Please insert {currentPrice.Price} cents:");

                //Store user input in a string
                string input = Console.ReadLine();

                //Convert the string to an int
                //Need to do some error handling on this to check for "" strings
                int inputInt = int.Parse(input);

                //Echo the input back to the user and report success
                Debug.WriteLine($"The user deposited {inputInt} cents.");
                Console.WriteLine($"You have inserted {inputInt} cents.");

                //Check to see if input was enough to buy a soda
                if (inputInt >= currentPrice.Price)
                {
                    //Inform the user that they paid enough to purchase a soda
                    Debug.WriteLine("The user inserted enough cents to purchase a soda.");
                    Console.WriteLine("You inserted enough cents to purchase a soda.");

                    //Start to dispense the soda
                    if (canRack.IsEmpty("Regular") == false) //First check to see if the rack is empty - regular soda for now
                    {
                        canRack.RemoveACanOf("Regular");     //Subtract a can
                        Debug.WriteLine("Dispensing one can of soda to the user");
                        Console.WriteLine("Thanks. Here is your soda.");
                    }
                    else if (canRack.IsEmpty("Regular") == true) //If the can rack is empty, inform the user.
                    {
                        Debug.WriteLine("The user attempted to buy a can of soda, but the rack was empty.");
                        Console.WriteLine("Sorry. That rack is empty.");
                    }
                }
                else //If there was not enough cents, inform the user.
                {
                    Debug.WriteLine("The user attempted to buy a can of soda, but the user did not insert enough cents.");
                    Console.WriteLine("You did not insert enough cents to purchase a soda.");
                }

                //Extra line space to prepare for the next run
                Console.WriteLine();
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            CanRack sodaRack = new CanRack();
            CoinBox changeBox = new CoinBox(new List<Coin> {
                new Coin(Coin.Denomination.QUARTER), new Coin(Coin.Denomination.DIME),
                new Coin(Coin.Denomination.NICKEL), new Coin(Coin.Denomination.QUARTER),
                new Coin(Coin.Denomination.QUARTER), new Coin(Coin.Denomination.DIME) });

            Console.WriteLine("******Welcome to the .NET Soda Vending Machine******");
            CanRack rack = new CanRack();
            PurchasePrice myPrice = new PurchasePrice(100);
          
            while (true)
            {
                Console.WriteLine("Enter '1' to purchase a soda.\nEnter '2' to exit");
                string userValue = Console.ReadLine();
                int convertedUserValue;
                if (int.TryParse(userValue, out convertedUserValue) == true)
                {
                    if (convertedUserValue == 1)
                    {
                        Console.WriteLine("Here is what we have in store");
                        rack.DisplayCanRack();
                        
                        Console.Write("\nPlease enter the Flavor you would like: ");
                        string UserFlavorInput = Console.ReadLine();

                        try
                        {
                            Flavor UserFlavor = FlavorOps.ToFlavor(UserFlavorInput);

                            if (!rack.IsEmpty(UserFlavor))
                            {
                                Console.Write("Please insert {0:C} into the machine ", myPrice.DecimalPrice);
                                decimal Total = 0;

                                while (Total < myPrice.DecimalPrice)
                                {
                                    string CoinString = Console.ReadLine();
                                    Coin CoinInput = new Coin(CoinString.ToUpper());
                                    Total = Total + CoinInput.ValueOf;
                                    Console.WriteLine("You inserted a {0}. Your total is {1}", CoinInput, Total);
                                }

                                rack.RemoveACanOf(UserFlavor);
                                Console.WriteLine("Dispensed 1 can of {0} Soda", UserFlavor);
                                Console.ReadLine();
                                continue;
                            }
                            else
                            {
                                Console.WriteLine("Sorry, we are out of {0}", UserFlavor);
                                continue;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Please try again and type in a valid flavor");
                        }
                    }
                    if (convertedUserValue == 2)
                    {
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Sorry, that is not a valid option");
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            CanRack sodaRack  = new CanRack();
            CoinBox changeBox = new CoinBox(new List <Coin> {
                new Coin(Coin.Denomination.QUARTER), new Coin(Coin.Denomination.DIME),
                new Coin(Coin.Denomination.NICKEL), new Coin(Coin.Denomination.QUARTER),
                new Coin(Coin.Denomination.QUARTER), new Coin(Coin.Denomination.DIME)
            });

            Console.WriteLine("******Welcome to the .NET Soda Vending Machine******");
            CanRack       rack    = new CanRack();
            PurchasePrice myPrice = new PurchasePrice(100);

            while (true)
            {
                Console.WriteLine("Enter '1' to purchase a soda.\nEnter '2' to exit");
                string userValue = Console.ReadLine();
                int    convertedUserValue;
                if (int.TryParse(userValue, out convertedUserValue) == true)
                {
                    if (convertedUserValue == 1)
                    {
                        Console.WriteLine("Here is what we have in store");
                        rack.DisplayCanRack();

                        Console.Write("\nPlease enter the Flavor you would like: ");
                        string UserFlavorInput = Console.ReadLine();

                        try
                        {
                            Flavor UserFlavor = FlavorOps.ToFlavor(UserFlavorInput);

                            if (!rack.IsEmpty(UserFlavor))
                            {
                                Console.Write("Please insert {0:C} into the machine ", myPrice.DecimalPrice);
                                decimal Total = 0;

                                while (Total < myPrice.DecimalPrice)
                                {
                                    string CoinString = Console.ReadLine();
                                    Coin   CoinInput  = new Coin(CoinString.ToUpper());
                                    Total = Total + CoinInput.ValueOf;
                                    Console.WriteLine("You inserted a {0}. Your total is {1}", CoinInput, Total);
                                }

                                rack.RemoveACanOf(UserFlavor);
                                Console.WriteLine("Dispensed 1 can of {0} Soda", UserFlavor);
                                Console.ReadLine();
                                continue;
                            }
                            else
                            {
                                Console.WriteLine("Sorry, we are out of {0}", UserFlavor);
                                continue;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Please try again and type in a valid flavor");
                        }
                    }
                    if (convertedUserValue == 2)
                    {
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Sorry, that is not a valid option");
                }
            }
        }