Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp4
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var fruit = Console.ReadLine();
  12. var dayOfWeek = Console.ReadLine();
  13. var calculation = double.Parse(Console.ReadLine());
  14.  
  15. string[] workdaysDays = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
  16. string[] weekendDays = { "Saturday", "Sunday" };
  17. string[] realFuits = { "banana", "apple", "orange", "grapefruit", "kiwi", "pineapple", "grapes" };
  18. double[] workdaysPrice = { 2.50, 1.20, 0.85, 1.45, 2.70, 5.50, 3.85 };
  19. double[] weekendPrice = { 2.70, 1.25, 0.90, 1.60, 3.00, 5.60, 4.20 };
  20.  
  21. Dictionary<string, double> workdays = new Dictionary<string, double>();
  22. for (int i = 0; i < realFuits.Length; i++) workdays.Add(realFuits[i], workdaysPrice[i]);
  23.  
  24. Dictionary<string, double> weekend = new Dictionary<string, double>();
  25. for (int i = 0; i < realFuits.Length; i++) weekend.Add(realFuits[i], weekendPrice[i]);
  26.  
  27. if (workdaysDays.Any(dayOfWeek.Contains)) TryParse(fruit, calculation, workdays);
  28. else if (weekendDays.Any(dayOfWeek.Contains)) TryParse(fruit, calculation, weekend);
  29. else Console.WriteLine("error");
  30. }
  31. private static void TryParse(string fruit, double calculation, Dictionary<string, double> workdays)
  32. {
  33. try
  34. {
  35. var price = workdays[fruit];
  36. Console.WriteLine($"{price * calculation:f2}");
  37. }
  38. catch (Exception)
  39. {
  40. Console.WriteLine("error");
  41. }
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement