예제 #1
0
 public void AddPastry(Pastry inputPastry, int numberOfTimes)
 {
     for (int i = 0; i < numberOfTimes; i++)
     {
         PastryList.Add(inputPastry);
     }
 }
예제 #2
0
        public decimal GetPastryPrice()
        {
            decimal outputPrice = 0;
            Dictionary <string, decimal>  pastryPrices = Pastry.GetOptions();
            Dictionary <decimal, decimal> typeCount    = new Dictionary <decimal, decimal>();

            foreach (KeyValuePair <string, decimal> entry in pastryPrices)
            {
                if (!typeCount.ContainsKey(entry.Value))
                {
                    typeCount.Add(entry.Value, 0);
                }
            }
            foreach (Pastry entry in PastryList)
            {
                typeCount[entry.Price] += 1;
            }
            foreach (KeyValuePair <decimal, decimal> entry in typeCount)
            {
                if (entry.Value > 0)
                {
                    decimal multiplesOfThree = Math.Floor(entry.Value / 3);
                    decimal pricePerThree    = (entry.Key * 3m) * (5m / 6m);
                    outputPrice += ((multiplesOfThree * pricePerThree) + ((entry.Value - (multiplesOfThree * 3)) * entry.Key));
                }
            }
            return(decimal.Round(outputPrice, 2));
        }
예제 #3
0
        public static void Main()
        {
            List <int> totals = new List <int> {
            };
            bool buyMore      = true;
            int  counter      = 0;

            Console.WriteLine("Welcome to Pierre's Bakery!");
            while (buyMore == true)
            {
                Console.WriteLine("Bread is $5 a loaf, but there is a sale for buy 2 get one free!");
                Console.WriteLine("Pastries are $2 each, but also on a sale 3 for $5!");
                Console.WriteLine("How many loaves of bread would you like to buy?");
                int   breadAmmount = int.Parse(Console.ReadLine());
                Bread breadClass   = new Bread(breadAmmount);

                Console.WriteLine("How many pastries would you like?");
                int    pastryAmmount = int.Parse(Console.ReadLine());
                Pastry pastryClass   = new Pastry(pastryAmmount);

                totals.Add(breadClass.AddRemainder() + pastryClass.AddRemainder());

                Console.WriteLine("Your total for bread is: $" + breadClass.AddRemainder() + ".");
                Console.WriteLine("And your total for pastries is: $" + pastryClass.AddRemainder() + ".");
                Console.WriteLine("Your total for both is: $" + totals[counter] + ".");
                Console.WriteLine("Would you like to buy more? Y/N");
                string buyMoreAnswer = Console.ReadLine();

                if (buyMoreAnswer == "Y")
                {
                    buyMore = true;
                    counter++;
                }
                else
                {
                    int grandTotal = 0;
                    for (int i = 0; i <= counter; i++)
                    {
                        grandTotal += totals[i];
                    }
                    Console.WriteLine("Your total for both is: $" + grandTotal + ".");
                    buyMore = false;
                }
            }

            Console.WriteLine("Would you like to shop again? Y/N");
            string continueAnswer = Console.ReadLine();

            if (continueAnswer == "Y")
            {
                Program.Main();
            }
            else
            {
                Console.WriteLine("Have a great day!");
            }
        }
예제 #4
0
        static void Main()
        {
            Console.BackgroundColor = ConsoleColor.DarkBlue;
            Console.ForegroundColor = ConsoleColor.Black;
            string title = "Welcome to Pierre's Bakery";

            Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + (title.Length / 2)) + "}", title).PadRight(Console.WindowWidth));
            Console.WriteLine("What type of bread would you like to add to your order? (white ($5), sourdough ($8), baguette ($3), italian ($7))");
            string breadType = Console.ReadLine();

            Console.WriteLine("How many loaves of bread would you like? (Buy 2 get your 3rd free)");
            Bread newBread = new Bread(breadType, Console.ReadLine());

            while (!newBread.isBreadTypeValid())
            {
                Console.WriteLine("-invalid input- Please choose a valid bread type (white, sourdough, baguette, italian)");
                newBread.BreadType = Console.ReadLine();
            }
            while (!newBread.IsBreadOrderNumberValid())
            {
                Console.WriteLine("-invalid input- Please enter a whole number of bread loafs ($5 each) to order (Buy 2 get your 3rd free, or buy 21 and two of them will be free):");
                newBread.BreadOrderNumberString = Console.ReadLine();
            }
            Console.WriteLine("How many pastries ($2 each, three for $5, 12 for $18) would you like? ");
            Pastry newPastry = new Pastry(Console.ReadLine());

            while (!newPastry.IsPastryOrderValid())
            {
                Console.WriteLine("-invalid input- Please enter a whole number of pastries ($2 each, three for $5, 12 for $18) to order:");
                newPastry.PastryOrderString = Console.ReadLine();
            }
            newBread.BreadCostCalc();
            newPastry.PastryCostCalc();
            int total = (newBread.BreadCost + newPastry.PastryCost);

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("   Your Order Details:");
            Console.WriteLine($"   {newBread.BreadType} loaves: ${newBread.BreadCost}");
            Console.WriteLine($"   Pastries: ${newPastry.PastryCost}");
            Console.WriteLine($"   Total: ${total}");
            Console.ForegroundColor = ConsoleColor.Black;
            Console.WriteLine("Would you like to make another order? (Y/N)");
            string newOrder = Console.ReadLine();

            if (newOrder == "Y")
            {
                Main();
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Thank you for visiting Pierre's Bakery! Have a nice day.");
            }
            Console.ResetColor();
        }
예제 #5
0
        private static void Checkout(Order userOrder)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            bool exitFlag = true;

            Console.WriteLine(CheckoutTextBuilder(userOrder));
            if (Bread.BreadSalesDetector(userOrder.BreadOrder))
            {
                Console.WriteLine("All bread is buy 2, get 1 free! Would you like to add a free loaf of bread to your cart? [Y/N]");
                string userResponse = Console.ReadLine();
                Console.Beep();
                if (userResponse == "Y" || userResponse == "y")
                {
                    userOrder.AddBread(1);
                    exitFlag = false;
                    Checkout(userOrder);
                }
            }
            if (Pastry.PastrySalesDetector(userOrder.PastryOrder))
            {
                Console.WriteLine("All pastries are 3 for $5! Would you like to add a pastry for only $1? [Y/N]");
                string userResponse = Console.ReadLine();
                Console.Beep();
                if (userResponse == "Y" || userResponse == "y")
                {
                    userOrder.AddPastry(1);
                    exitFlag = false;
                    Checkout(userOrder);
                }
            }
            if (exitFlag)
            {
                Console.WriteLine($"Your total comes to ${userOrder.TotalPrice()}");
                Console.WriteLine("Thank you for shopping at Pierre's Bakery!");
            }
        }