Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace FruitShop
  5. {
  6.     class FruitShop
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var product = Console.ReadLine();
  11.             var day = Console.ReadLine();
  12.             var quantity = double.Parse(Console.ReadLine());
  13.             var workDays = new HashSet<string>()
  14.             {
  15.                 "Monday","Tuesday","Wednesday","Thursday","Friday"
  16.             };
  17.  
  18.             var weekend = new HashSet<string>()
  19.             {
  20.                 "Saturday","Sunday"
  21.             };
  22.  
  23.             var workDayPricing = FillPricing(2.50, 1.20, 0.85, 1.45, 2.70, 5.50, 3.85);
  24.             var weekendPricing = FillPricing(2.70, 1.25, 0.90, 1.60, 3.00, 5.60, 4.20);
  25.  
  26.             if (workDays.Contains(day))
  27.             {
  28.                 if (workDayPricing.ContainsKey(product))
  29.                 {
  30.                     Console.WriteLine("{0:F2}", workDayPricing[product] * quantity);
  31.                 }
  32.                 else
  33.                 {
  34.                     Console.WriteLine("error");
  35.                 }
  36.             }
  37.             else if (weekend.Contains(day))
  38.             {
  39.                 if (weekendPricing.ContainsKey(product))
  40.                 {
  41.                     Console.WriteLine("{0:F2}", weekendPricing[product] * quantity);
  42.                 }
  43.                 else
  44.                 {
  45.                     Console.WriteLine("error");
  46.                 }
  47.             }
  48.             else
  49.             {
  50.                 Console.WriteLine("error");
  51.             }
  52.         }
  53.  
  54.         private static Dictionary<string, double> FillPricing(double d1, double d2, double d3,
  55.             double d4, double d5, double d6, double d7)
  56.         {
  57.             var pricing = new Dictionary<string, double>();
  58.             pricing.Add("banana", d1);
  59.             pricing.Add("apple", d2);
  60.             pricing.Add("orange", d3);
  61.             pricing.Add("grapefruit", d4);
  62.             pricing.Add("kiwi", d5);
  63.             pricing.Add("pineapple", d6);
  64.             pricing.Add("grapes", d7);
  65.  
  66.             return pricing;
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement