Advertisement
desislava_topuzakova

Program.cs

Jul 7th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace AlgorithmsRetakeExam
  5. {
  6. class Program
  7. {
  8. static Hotel hotel = new Hotel("Hotel1");
  9.  
  10. static void Main(string[] args)
  11. {
  12. string line;
  13.  
  14. while ("END" != (line = Console.ReadLine()))
  15. {
  16. string[] cmdArgs = line.Split(' ');
  17.  
  18. switch (cmdArgs[0])
  19. {
  20. case "Add":
  21. AddDog(cmdArgs[1], int.Parse(cmdArgs[2]));
  22. break;
  23. case "AverageAge":
  24. AverageAge();
  25. break;
  26. case "FilterDogs":
  27. FilterDogsByAge(int.Parse(cmdArgs[1]));
  28. break;
  29. case "SortByName":
  30. SortAscendingByName();
  31. break;
  32. case "SortByAge":
  33. SortDescendingByAge();
  34. break;
  35. case "CheckDog":
  36. CheckDogIsInHotel(cmdArgs[1]);
  37. break;
  38. case "Print":
  39. ProvideInformationAboutAllDogs();
  40. break;
  41. }
  42. }
  43. }
  44.  
  45. private static void ProvideInformationAboutAllDogs()
  46. {
  47. string[] info = hotel.ProvideInformationAboutAllDogs();
  48. foreach (string item in info)
  49. {
  50. Console.WriteLine(item);
  51. }
  52. }
  53.  
  54. private static void CheckDogIsInHotel(string name)
  55. {
  56. if (hotel.CheckDogIsInHotel(name))
  57. {
  58. Console.WriteLine($"Dog {name} is in the hotel.");
  59. }
  60. else
  61. {
  62. Console.WriteLine($"Dog {name} is not in the hotel.");
  63. }
  64. }
  65. private static void SortDescendingByAge()
  66. {
  67. hotel.SortDescendingByAge();
  68. Console.WriteLine("The youngest dog is: " + hotel.Dogs[hotel.Dogs.Count - 1].Name);
  69. }
  70. private static void SortAscendingByName()
  71. {
  72. hotel.SortAscendingByName();
  73. Console.WriteLine("First dog is: " + hotel.Dogs[0].Name);
  74. }
  75. private static void FilterDogsByAge(int age)
  76. {
  77. List<string> dogs = hotel.FilterDogsByAge(age);
  78. Console.WriteLine("Filtered dogs: " + string.Join(", ", dogs));
  79. }
  80.  
  81. private static void AverageAge()
  82. {
  83. double averageAge = hotel.AverageAge();
  84. Console.WriteLine($"Average age: {averageAge:F2}");
  85. }
  86.  
  87. private static void AddDog(string name, int age)
  88. {
  89. hotel.AddDog(name, age);
  90. Console.WriteLine($"Added dog {name}.");
  91. }
  92. }
  93. }
  94.  
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement