Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Problem06VehicleCatalogue
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. List<Car> cars = new List<Car>();
  11. List<Truck> trucks = new List<Truck>();
  12. int numberOfCars = 0;
  13. int numberOfTrucks = 0;
  14. double horsePowerCars = 0;
  15. double horsePowerTrucks = 0;
  16.  
  17. while (true)
  18. {
  19. string command = Console.ReadLine();
  20.  
  21. if (command == "End") break;
  22.  
  23. string[] inputAsArray = command.Split();
  24.  
  25. string typeOfVehicle = inputAsArray[0];
  26. string model = inputAsArray[1];
  27. string color = inputAsArray[2];
  28. int horsePower = int.Parse(inputAsArray[3]);
  29.  
  30. if (typeOfVehicle == "car")
  31. {
  32. Car newCar = new Car()
  33. {
  34. Model = model,
  35. Color = color,
  36. HorsePower = horsePower
  37. };
  38.  
  39. numberOfCars += 1;
  40. horsePowerCars += horsePower;
  41. cars.Add(newCar);
  42. }
  43. else
  44. {
  45. Truck newTruck = new Truck()
  46. {
  47. Model = model,
  48. Color = color,
  49. HorsePower = horsePower
  50. };
  51.  
  52. numberOfTrucks += 1;
  53. horsePowerTrucks += horsePower;
  54. trucks.Add(newTruck);
  55. }
  56. }
  57.  
  58. while (true)
  59. {
  60. string command = Console.ReadLine();
  61. if (command == "Close the Catalogue")
  62. {
  63. break;
  64. }
  65.  
  66. string model = command;
  67.  
  68. foreach (var car in cars)
  69. {
  70. if (car.Model == model)
  71. {
  72. //Type: {typeOfVehicle}
  73. //Model: {modelOfVehicle}
  74. //Color: {colorOfVehicle}
  75. //Horsepower: {horsepowerOfVehicle}
  76.  
  77. Console.WriteLine($"Type: Car");
  78. Console.WriteLine($"Model: {car.Model}");
  79. Console.WriteLine($"Color: {car.Color}");
  80. Console.WriteLine($"Horsepower: {car.HorsePower}");
  81. break;
  82. }
  83. }
  84.  
  85. foreach (var truck in trucks)
  86. {
  87. if (truck.Model == model)
  88. {
  89. //Type: {typeOfVehicle}
  90. //Model: {modelOfVehicle}
  91. //Color: {colorOfVehicle}
  92. //Horsepower: {horsepowerOfVehicle}
  93.  
  94. Console.WriteLine($"Type: Truck");
  95. Console.WriteLine($"Model: {truck.Model}");
  96. Console.WriteLine($"Color: {truck.Color}");
  97. Console.WriteLine($"Horsepower: {truck.HorsePower}");
  98. break;
  99. }
  100. }
  101. }
  102.  
  103. Console.WriteLine($"Cars have average horsepower of: {(horsePowerCars / numberOfCars):F2}.");
  104. Console.WriteLine($"Trucks have average horsepower of: {(horsePowerTrucks / numberOfTrucks):F2}.");
  105. }
  106. }
  107.  
  108. class Car
  109. {
  110. public string Model;
  111. public string Color;
  112. public int HorsePower;
  113. }
  114.  
  115. class Truck
  116. {
  117. public string Model;
  118. public string Color;
  119. public int HorsePower;
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement