Advertisement
svetlyoek

Untitled

Feb 28th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp191
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11.  
  12. List<Car> cars = new List<Car>();
  13. List<Truck> trucks = new List<Truck>();
  14. string[] data = new string[4];
  15. while (true)
  16. {
  17. data = Console.ReadLine().Split().ToArray();
  18. if (data[0] == "End")
  19. {
  20. break;
  21. }
  22. string type = data[0];
  23. string model = data[1];
  24. string color = data[2];
  25. int horsePower = int.Parse(data[3]);
  26. if (data[0] == "car")
  27. {
  28.  
  29. Car car = new Car();
  30. {
  31. car.Type = type;
  32. car.Model = model;
  33. car.Color = color;
  34. car.HorsePower = horsePower;
  35. }
  36. cars.Add(car);
  37. }
  38. else if (data[0] == "truck")
  39. {
  40. Truck truck = new Truck()
  41. {
  42. Type = type,
  43. Model = model,
  44. Color = color,
  45. HorsePower = horsePower
  46. };
  47. trucks.Add(truck);
  48. }
  49. }
  50. while (true)
  51. {
  52. string newModels = Console.ReadLine();
  53. if (newModels == "Close the Catalogue")
  54. {
  55. break;
  56. }
  57.  
  58. for (int i = 0; i < cars.Count; i++)
  59. {
  60. if (cars[i].Model.Contains(newModels) && cars.Count > 0)
  61.  
  62. {
  63.  
  64. Console.WriteLine($"Type: Car");
  65. Console.WriteLine($"Model: {cars[i].Model}");
  66. Console.WriteLine($"Color: {cars[i].Color}");
  67. Console.WriteLine($"Horsepower: {cars[i].HorsePower}");
  68. }
  69. }
  70.  
  71.  
  72. for (int i = 0; i < trucks.Count; i++)
  73. {
  74. if (trucks[i].Model.Contains(newModels) && trucks.Count > 0)
  75.  
  76. {
  77.  
  78. Console.WriteLine($"Type: Truck");
  79. Console.WriteLine($"Model: {trucks[i].Model}");
  80. Console.WriteLine($"Color: {trucks[i].Color}");
  81. Console.WriteLine($"Horsepower: {trucks[i].HorsePower}");
  82. }
  83. }
  84.  
  85. }
  86.  
  87. int carsCount = 0;
  88. int trucksCount = 0;
  89. double carsHorsePower = 0.0d;
  90. double trucksHorsePower = 0.0d;
  91.  
  92. for (int i = 0; i < cars.Count; i++)
  93. {
  94. if (cars[i].Type == "car" )
  95. {
  96. carsCount++;
  97. carsHorsePower += cars[i].HorsePower;
  98. }
  99.  
  100. }
  101.  
  102.  
  103. for (int i = 0; i < trucks.Count; i++)
  104. {
  105. if (trucks[i].Type == "truck")
  106. {
  107. trucksCount++;
  108. trucksHorsePower += trucks[i].HorsePower;
  109. }
  110. }
  111. Console.WriteLine($"Cars have average horsepower of: {(carsHorsePower / carsCount):f2}.");
  112. Console.WriteLine($"Trucks have average horsepower of: {(trucksHorsePower / trucksCount):f2}.");
  113.  
  114.  
  115. }
  116. }
  117. }
  118.  
  119. public class Car
  120. {
  121. public string Type { get; set; }
  122. public string Model { get; set; }
  123. public string Color { get; set; }
  124. public int HorsePower { get; set; }
  125.  
  126. }
  127.  
  128. public class Truck
  129. {
  130. public string Type { get; set; }
  131. public string Model { get; set; }
  132. public string Color { get; set; }
  133. public int HorsePower { get; set; }
  134.  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement