Advertisement
fbinnzhivko

01.00 Fruit Market

Apr 17th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 KB | None | 0 0
  1. using System;
  2. public class FruitMarket
  3. {
  4.     public static void Main()
  5.     {
  6.         string dayOfWeek = Console.ReadLine();
  7.         decimal quantity1 = decimal.Parse(Console.ReadLine());
  8.         string product1 = Console.ReadLine();
  9.         decimal quantity2 = decimal.Parse(Console.ReadLine());
  10.         string product2 = Console.ReadLine();
  11.         decimal quantity3 = decimal.Parse(Console.ReadLine());
  12.         string product3 = Console.ReadLine();
  13.  
  14.         decimal totalPrice =
  15.             quantity1 * GetPrice(product1, dayOfWeek) +
  16.             quantity2 * GetPrice(product2, dayOfWeek) +
  17.             quantity3 * GetPrice(product3, dayOfWeek);
  18.         Console.WriteLine("{0:f2}", totalPrice);
  19.     }
  20.     static decimal GetPrice(string productName, string dayOfWeek)
  21.         // Assign standard price and check for fruit
  22.     {
  23.         decimal price = 0;
  24.         bool isFruit = false;
  25.         switch (productName)
  26.         {
  27.             case "banana": price = 1.80m; isFruit = true; break;
  28.             case "cucumber": price = 2.75m; break;
  29.             case "tomato": price = 3.20m; break;
  30.             case "orange": price = 1.60m; isFruit = true; break;
  31.             case "apple": price = 0.86m; isFruit = true; break;
  32.         }                                       // Apply the daily discounts
  33.         switch (dayOfWeek)
  34.         {
  35.             case "Friday":
  36.                 price = price * 0.90m;
  37.                 break;
  38.             case "Sunday":
  39.                 price = price * 0.95m;
  40.                 break;
  41.             case "Tuesday":
  42.                 if (isFruit)
  43.                     price = price * 0.80m;
  44.                 break;
  45.             case "Wednesday":
  46.                 if (!isFruit)
  47.                     price = price * 0.90m;
  48.                 break;
  49.             case "Thursday":
  50.                 if (productName == "banana")
  51.                     price = price * 0.70m;
  52.                 break;
  53.         }
  54.         return price;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement