Advertisement
Tanina80

4.07.FruitShopContainsKey

Jun 30th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. class FruitShop
  7. {
  8. static void Main()
  9. {
  10. string fruit = Console.ReadLine();
  11. string dayOfWeek = Console.ReadLine();
  12. double quantity = double.Parse(Console.ReadLine());
  13. double price;
  14. var daysOfWeek = new List<string> { "Monday", "Tuesday", "Wednesday", "Thirsday", "Friday" };
  15. var daysOfWeekend = new List<string> { "Saturday", "Sunday" };
  16.  
  17. Dictionary<string, double> pricesWeek = new Dictionary<string, double>
  18. { { "banana", 2.50 }, { "apple", 1.20}, { "orange", 0.85},
  19. {"grapefruit", 1.45}, {"kiwi", 2.70}, { "pineapple", 5.50}, { "grapes", 3.85}
  20. };
  21. Dictionary<string, double> pricesWeekend = new Dictionary<string, double>
  22. { { "banana", 2.70 }, { "apple", 1.25}, { "orange", 0.90},
  23. {"grapefruit", 1.60}, {"kiwi", 3.00}, { "pineapple", 5.60}, { "grapes", 4.20}
  24. };
  25.  
  26. if ((daysOfWeek.Contains(dayOfWeek)) && (pricesWeek.ContainsKey(fruit)))
  27. {
  28. price = quantity * pricesWeek[fruit];
  29. Console.WriteLine("{0:f2}", price);
  30. }
  31. else if ((daysOfWeekend.Contains(dayOfWeek)) && (pricesWeekend.ContainsKey(fruit)))
  32. {
  33. price = quantity * pricesWeekend[fruit];
  34. Console.WriteLine("{0:f2}", price);
  35. }
  36. else
  37. {
  38. Console.WriteLine("error");
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement