Advertisement
fbinnzhivko

01.02 FruitMarket

Apr 17th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. class FruitMarket
  4. {
  5.     static void Main()
  6.     {
  7.         string dayOfWeek = Console.ReadLine();
  8.  
  9.         double totalPrice = 0;
  10.         //Dictionary<double, string> orders = new Dictionary<double, string>();
  11.         for (int i = 0; i < 3; i++)
  12.         {
  13.             double quantity = double.Parse(Console.ReadLine());
  14.             string product = Console.ReadLine();
  15.  
  16.             if (dayOfWeek == "Friday" || dayOfWeek == "Sunday")
  17.             {
  18.                 totalPrice += quantity * PriceList(product) * Discounts(dayOfWeek);
  19.             }
  20.             else if (dayOfWeek == "Tuesday" && (product == "banana" || product == "apple" || product == "orange"))
  21.             {
  22.                 totalPrice += quantity * PriceList(product) * Discounts(dayOfWeek);
  23.             }
  24.             else if (dayOfWeek == "Wednesday" && (product == "tomato" || product == "cucumber"))
  25.             {
  26.                 totalPrice += quantity * PriceList(product) * Discounts(dayOfWeek);
  27.             }
  28.             else if (dayOfWeek == "Thursday" && product == "banana")
  29.             {
  30.                 totalPrice += quantity * PriceList(product) * Discounts(dayOfWeek);
  31.             }
  32.             else
  33.             {
  34.                 totalPrice += quantity * PriceList(product);
  35.             }
  36.  
  37.         }
  38.         Console.WriteLine("{0, 0:F2}", totalPrice);
  39.     }
  40.  
  41.     public static double Discounts(string dayOfWeek)
  42.     {
  43.         Dictionary<string, double> discounts = new Dictionary<string, double>()
  44.         {
  45.             {"Friday", 0.9},
  46.             {"Sunday", 0.95},
  47.             {"Tuesday", 0.8},
  48.             {"Wednesday", 0.9},
  49.             {"Thursday", 0.7}
  50.         };
  51.  
  52.         return discounts[dayOfWeek];
  53.     }
  54.  
  55.     public static double PriceList(string product)
  56.     {
  57.         Dictionary<string, double> priceList = new Dictionary<string, double>()
  58.         {
  59.             {"banana", 1.80},
  60.             {"cucumber", 2.75},
  61.             {"tomato", 3.20},
  62.             {"orange", 1.60},
  63.             {"apple", 0.86}
  64.         };
  65.         return priceList[product];
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement