Advertisement
zarkoy

Untitled

Nov 12th, 2018
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _06_VehicleCatalogue
  6. {
  7. public class Vehicle
  8. {
  9. public Vehicle(string typeOfVehicle, string model, string color, int horespower)
  10. {
  11. this.TypeOfVehicle = typeOfVehicle;
  12. this.Model = model;
  13. this.Color = color;
  14. this.Horsepower = horespower;
  15. }
  16.  
  17. public string TypeOfVehicle { get; set; }
  18.  
  19. public string Model { get; set; }
  20.  
  21. public string Color { get; set; }
  22.  
  23. public int Horsepower { get; set; }
  24.  
  25. public override string ToString()
  26. {
  27. return $"Type: {this.TypeOfVehicle} {Environment.NewLine}Model: {this.Model} {Environment.NewLine}Color: {this.Color} {Environment.NewLine}Horsepower: {this.Horsepower}";
  28. }
  29. }
  30.  
  31. public class Program
  32. {
  33. public static void Main()
  34. {
  35. var listOfVehicles = new List<Vehicle>();
  36.  
  37. var cars = new List<Vehicle>();
  38. var trucks = new List<Vehicle>();
  39.  
  40.  
  41. while (true)
  42. {
  43.  
  44. var input = Console.ReadLine();
  45.  
  46. if (input == "End")
  47. {
  48. break;
  49. }
  50.  
  51. var splittedInput = input
  52. .Split()
  53. .ToList();
  54.  
  55. var type = splittedInput[0];
  56. var model = splittedInput[1];
  57. var color = splittedInput[2];
  58. var horsepower = int.Parse(splittedInput[3]);
  59.  
  60. var vehicle = new Vehicle(type, model, color, horsepower);
  61.  
  62. listOfVehicles.Add(vehicle);
  63.  
  64. if (type == "car")
  65. {
  66. cars.Add(vehicle);
  67. }
  68. else if (type == "truck")
  69. {
  70. trucks.Add(vehicle);
  71. }
  72.  
  73. }
  74.  
  75. while (true)
  76. {
  77. var modelInput = Console.ReadLine();
  78.  
  79. if (modelInput == "Close the Catalogue")
  80. {
  81. break;
  82. }
  83.  
  84. var vehicle = listOfVehicles
  85. .Where(x => x.Model == modelInput)
  86. .First();
  87. Console.WriteLine(vehicle);
  88. }
  89.  
  90. if (cars.Count > 0)
  91. {
  92. Console.WriteLine($"Cars have average horsepower of: {cars.Select(x=>x.Horsepower).Average():f2}");
  93. }
  94. else
  95. {
  96. Console.WriteLine("Cars have average horsepower of: 0.00");
  97. }
  98.  
  99. if (trucks.Count > 0)
  100. {
  101. Console.WriteLine($"Trucks have average horsepower of: {trucks.Select(x => x.Horsepower).Average():f2}");
  102. }
  103. else
  104. {
  105. Console.WriteLine($"Trucks have average horsepower of: 0.00");
  106. }
  107. }
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement