Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace VehicleCatalogue
  8. {
  9.  
  10. public class Vehicles
  11. {
  12. public static string FirstCharToUpper(string input)
  13. {
  14. if (String.IsNullOrEmpty(input))
  15. throw new ArgumentException("ARGH!");
  16. return input.First().ToString().ToUpper() + input.Substring(1);
  17. }
  18.  
  19.  
  20. public string Type { get; set; }
  21. public string Model { get; set; }
  22. public string Color { get; set; }
  23. public int Horsepower { get; set; }
  24.  
  25. public Vehicles(string type, string model, string color, int horsepower)
  26. {
  27. this.Type = type;
  28. this.Model = model;
  29. this.Color = color;
  30. this.Horsepower = horsepower;
  31. }
  32.  
  33.  
  34. }
  35.  
  36. class Program
  37. {
  38.  
  39.  
  40. static void Main(string[] args)
  41. {
  42. List<Vehicles> car = new List<Vehicles>();
  43. List<Vehicles> truck = new List<Vehicles>();
  44. while (true)
  45. {
  46. List<string> inPut = Console.ReadLine()
  47. .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  48. .ToList();
  49. if(inPut[0] == "End")
  50. {
  51. break;
  52. }
  53. string type = inPut[0];
  54. string model = inPut[1];
  55. string color = inPut[2];
  56. int horsepower = int.Parse(inPut[3]);
  57. Vehicles sortedVehicles = new Vehicles(type, model, color, horsepower);
  58. if(type == "car" || type == "Car")
  59. {
  60. car.Add(sortedVehicles);
  61. }
  62. if (type == "truck" || type == "Truck")
  63. {
  64. truck.Add(sortedVehicles);
  65. }
  66.  
  67. }
  68. while (true)
  69. {
  70. List<string> modelsOfVehicles = Console.ReadLine()
  71. .Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)
  72. .ToList();
  73. if(modelsOfVehicles[0] == "Close the Catalogue")
  74. {
  75. break;
  76. }
  77. string findModel = modelsOfVehicles[0];
  78. foreach (var item in car)
  79. {
  80. if (item.Model == findModel)
  81. {
  82.  
  83. Console.WriteLine("Type: " + Vehicles.FirstCharToUpper(item.Type));
  84. Console.WriteLine("Model: " + item.Model);
  85. Console.WriteLine("Color: " + item.Color);
  86. Console.WriteLine("Horsepower: " + item.Horsepower);
  87. break;
  88. }
  89. }
  90. foreach (var item in truck)
  91. {
  92. if (item.Model == findModel)
  93. {
  94. Console.WriteLine("Type: " + char.ToUpper(item.Type[0]) + item.Type.Substring(1));
  95. Console.WriteLine("Model: " + item.Model);
  96. Console.WriteLine("Color: " + item.Color);
  97. Console.WriteLine("Horsepower: " + item.Horsepower);
  98. }
  99. }
  100. }
  101. double sumCar = car.Average(x=>x.Horsepower);
  102. double sumTruck = truck.Average(x => x.Horsepower);
  103. if (car.Count > 0)
  104. {
  105. Console.WriteLine($"Cars have average horsepower of: {sumCar:f2}.");
  106.  
  107. }
  108. else
  109. {
  110. Console.WriteLine($"Cars have average horsepower of: {0:f2}.");
  111. }
  112.  
  113. if (truck.Count > 0)
  114. {
  115. Console.WriteLine($"Trucks have average horsepower of: {sumTruck:f2}.");
  116. }
  117. else
  118. {
  119. Console.WriteLine($"Trucks have average horsepower of: {0:f2}.");
  120. }
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement