Advertisement
AlexMAlex

Untitled

Feb 23rd, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Vehicle_Catalogue
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. List<Vehicle> autos = new List<Vehicle>();
  11. string input = string.Empty;
  12. double truckHorsePower = 0;
  13. int counterTruck = 0;
  14. double carHorsePower = 0;
  15. int counterCar = 0;
  16. while ((input=Console.ReadLine())!="End")
  17. {
  18. string[] data = input.Split(' ');
  19. Vehicle currAuto = new Vehicle(data[0], data[1], data[2], int.Parse(data[3]));
  20. if (data[0]=="truck")
  21. {
  22. currAuto.Type="Truck";
  23. truckHorsePower += currAuto.Horsepower;
  24. counterTruck++;
  25. }
  26. else
  27. {
  28. currAuto.Type = "Car";
  29. carHorsePower += currAuto.Horsepower;
  30. counterCar++;
  31. }
  32. autos.Add(currAuto);
  33.  
  34. }
  35.  
  36. string currModel = string.Empty;
  37. while ((currModel = Console.ReadLine()) != "Close the Catalogue")
  38. {
  39. foreach (Vehicle auto in autos)
  40. {
  41. if (auto.Model == currModel)
  42. {
  43. Console.WriteLine($"Type: {auto.Type}");
  44. Console.WriteLine($"Model: {auto.Model}");
  45. Console.WriteLine($"Color: {auto.Color}");
  46. Console.WriteLine($"Horsepower: {auto.Horsepower}");
  47. }
  48. }
  49. }
  50. double midCarHorsePower = carHorsePower / counterCar;
  51. double midTruckHorsePower = truckHorsePower / counterTruck;
  52. Console.WriteLine($"Cars have average horsepower of: { midCarHorsePower:F2}.");
  53. Console.WriteLine($"Trucks have average horsepower of: { midTruckHorsePower:F2}.");
  54. }
  55. }
  56. class Vehicle
  57. {
  58. public Vehicle(string type, string model, string color, int horsepower)
  59. {
  60. this.Type = type;
  61. this.Model = model;
  62. this.Color = color;
  63. this.Horsepower = horsepower;
  64.  
  65. }
  66. public string Type { get; set; }
  67. public string Model { get; set; }
  68. public string Color { get; set; }
  69. public int Horsepower { get; set; }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement