// OPTIONAL – returns true if the rack is full of a specified flavor
        // false otherwise
        public Boolean IsFull(string FlavorOfBinToBeChecked)
        {
            FlavorOfBinToBeChecked = FlavorOfBinToBeChecked.ToUpper();
            Flavor flavorEnumeral = FlavorOps.ToFlavor(FlavorOfBinToBeChecked);

            Debug.WriteLine("Checking if can rack is full of flavor {0}", FlavorOfBinToBeChecked, DUMMYARGUMENT);
            return(rack[flavorEnumeral] == BINSIZE);
        }
        //  This public void will empty the rack of a given flavor.
        public void EmptyCanRackOf(string FlavorOfBinToBeEmptied)
        {
            FlavorOfBinToBeEmptied = FlavorOfBinToBeEmptied.ToUpper();
            Flavor flavorEnumeral = FlavorOps.ToFlavor(FlavorOfBinToBeEmptied);

            Debug.WriteLine("Emptying can rack of flavor {0}", FlavorOfBinToBeEmptied);
            rack[flavorEnumeral] = EMPTYBIN;
        }
        // OPTIONAL – return true if the rack is empty of a specified flavor
        // false otherwise
        public Boolean IsEmpty(string FlavorOfBinToBeChecked)
        {
            FlavorOfBinToBeChecked = FlavorOfBinToBeChecked.ToUpper();
            Debug.WriteLine("Checking if can rack is empty of flavor {0}", FlavorOfBinToBeChecked, DUMMYARGUMENT);
            // convert the string Flavor into the appropriate int value
            Flavor flavorEnumeral = FlavorOps.ToFlavor(FlavorOfBinToBeChecked);

            return(rack[flavorEnumeral] == EMPTYBIN);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            PurchasePrice sodaPrice = new PurchasePrice(1.0M);
            CanRack       sodaRack  = new CanRack();

            Console.WriteLine("Welcome to the .NET C# Soda Vending Machine");

            Boolean timeToExit = false;

            do
            {
                sodaRack.DisplayCanRack();
                Console.Write("Please insert {0:c} worth of coins: ", sodaPrice.PriceDecimal);

                decimal totalValueInserted = 0M;
                while (totalValueInserted < sodaPrice.PriceDecimal)
                {
                    // get the coin inserted
                    string coinNameInserted = Console.ReadLine().ToUpper();
                    Coin   coinInserted     = new Coin(coinNameInserted);
                    Console.WriteLine("You have inserted a {0} worth {1:c}", coinInserted, coinInserted.ValueOf);

                    // running total of the value of the coins inserted
                    totalValueInserted += coinInserted.ValueOf;
                    Console.WriteLine("Total value inserted is {0:c}", totalValueInserted);
                }

                // select a flavor of soda
                Boolean canDispensed = false;
                while (!canDispensed)
                {
                    Console.Write("What flavor would you like? : ");
                    string flavorName = Console.ReadLine().ToUpper();

                    // Well, this used to be trouble.
                    Flavor flavor = FlavorOps.ToFlavor(flavorName);

                    if (!sodaRack.IsEmpty(flavor))
                    {
                        sodaRack.RemoveACanOf(flavor);
                        Console.WriteLine("Thanks, here is your can of {0}.", flavor);
                        canDispensed = true;
                    }
                    else
                    {
                        Console.WriteLine("We are out of {0}", flavor);
                    }
                }

                Console.Write("Exit the vending machine? (y/n): ");
                string response = Console.ReadLine();
                timeToExit = response.Trim().ToUpper().StartsWith("Y");
            } while (!timeToExit);
        }
 //  This method will remove a can of the specified flavor from the rack.
 public void RemoveACanOf(string FlavorOfCanToBeRemoved)
 {
     FlavorOfCanToBeRemoved = FlavorOfCanToBeRemoved.ToUpper();
     if (IsEmpty(FlavorOfCanToBeRemoved))
     {
         Debug.WriteLine("*** Failed attempt to remove a can of {0} from an empty rack", FlavorOfCanToBeRemoved, DUMMYARGUMENT);
     }
     else
     {
         Debug.WriteLine("removing a can of {0} flavored soda to the rack", FlavorOfCanToBeRemoved, DUMMYARGUMENT);
         // convert the string Flavor into the appropriate Flavor value
         Flavor flavorEnumeral = FlavorOps.ToFlavor(FlavorOfCanToBeRemoved);
         rack[flavorEnumeral]--;
     }
 }
 //  This method adds a can of the specified flavor to the rack.
 public void AddACanOf(string FlavorOfCanToBeAdded)
 {
     FlavorOfCanToBeAdded = FlavorOfCanToBeAdded.ToUpper();
     if (IsFull(FlavorOfCanToBeAdded))
     {
         Debug.WriteLine("*** Failed attempt to add a can of {0} to a full rack", FlavorOfCanToBeAdded, DUMMYARGUMENT);
     }
     else
     {
         Debug.WriteLine("adding a can of {0} flavored soda to the rack", FlavorOfCanToBeAdded, DUMMYARGUMENT);
         // convert the string Flavor into the Flavor value
         Flavor flavorEnumeral = FlavorOps.ToFlavor(FlavorOfCanToBeAdded);
         rack[flavorEnumeral]++;
     }
 }