Guest User

Untitled

a guest
Jun 24th, 2017
404
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace VehicleCatalgoue
  6. {
  7. class VehicleCatalgoue
  8. {
  9. static void Main()
  10. {
  11. var input = Console.ReadLine();
  12. var vehicleList = new List<Vehicle>();
  13. while (input != "End")
  14. {
  15. var inputSplit = input
  16. .Split(' ')
  17. .ToArray();
  18.  
  19. var vehicle = new Vehicle();
  20. vehicle.Type = inputSplit[0][0].ToString().ToUpper() + inputSplit[0].Substring(1);
  21. vehicle.Model = inputSplit[1];
  22. vehicle.Color = inputSplit[2];
  23. vehicle.Horsepower = int.Parse(inputSplit[3]);
  24. vehicleList.Add(vehicle);
  25. input = Console.ReadLine();
  26. }
  27. input = Console.ReadLine();
  28. while (input != "Close the Catalogue")
  29. {
  30. var vehicle = vehicleList.Where(x => x.Model == input).First();
  31. Console.WriteLine($"Type: {vehicle.Type}");
  32. Console.WriteLine($"Model: {vehicle.Model}");
  33. Console.WriteLine($"Color: {vehicle.Color}");
  34. Console.WriteLine($"Horsepower: {vehicle.Horsepower}");
  35. input = Console.ReadLine();
  36. }
  37. if (vehicleList.Where(x => x.Type == "Car").Count() > 0)
  38. Console.WriteLine($"Cars have average horsepower of: {vehicleList.Where(x => x.Type == "Car").Select(x => x.Horsepower).Average():F2}.");
  39. else Console.WriteLine($"Cars have average horsepower of: 0.00.");
  40. if (vehicleList.Where(x => x.Type == "Truck").Count() > 0)
  41. Console.WriteLine($"Trucks have average horsepower of: {vehicleList.Where(x => x.Type == "Truck").Select(x => x.Horsepower).Average():F2}.");
  42. else Console.WriteLine($"Trucks have average horsepower of: 0.00.");
  43. }
  44. }
  45.  
  46. class Vehicle
  47. {
  48. public string Type { get; set; }
  49. public string Model { get; set; }
  50. public string Color { get; set; }
  51. public int Horsepower { get; set; }
  52. }
  53. }
RAW Paste Data