Guest User

Untitled

a guest
Jan 17th, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Numerics;
  7.  
  8. namespace ConsoleApp7
  9. {
  10. class Program
  11. {
  12. static void Main()
  13. {
  14. List<Vehicle> Vehicles = new List<Vehicle>();
  15. List<Vehicle> vehiclesPrint = new List<Vehicle>();
  16. double sumCars=0;
  17. int countCars=0;
  18. double sumTrucks = 0;
  19. int countTrucks = 0;
  20. string input01;
  21. while ((input01=Console.ReadLine())!="End")
  22. {
  23.  
  24. string[] inputData = input01.Split(' ');
  25. Vehicle vehicle01 = new Vehicle(inputData[0], inputData[1], inputData[2], int.Parse(inputData[3]));
  26. Vehicles.Add(vehicle01);
  27. if (inputData[0]=="car")
  28. {
  29. sumCars += int.Parse(inputData[3]);
  30. countCars++;
  31. }else if (inputData[0] == "truck")
  32. {
  33. sumTrucks +=int.Parse(inputData[3]);
  34. countTrucks++;
  35. }
  36.  
  37. }
  38. string input02;
  39. while ((input02 = Console.ReadLine()) != "Close the Catalogue")
  40. {
  41. if (Vehicles.Any(x=>x.modelOfVehicle==input02))
  42. {
  43.  
  44. vehiclesPrint.Add(Vehicles.First(x => x.modelOfVehicle == input02));
  45. }
  46. }
  47.  
  48. foreach (Vehicle vehicle in vehiclesPrint)
  49. {
  50. string capitalizedString = char.ToUpper(vehicle.typeOfVehicle[0]) + vehicle.typeOfVehicle.Substring(1);
  51. Console.WriteLine($"Type: {capitalizedString}");
  52. Console.WriteLine($"Model: {vehicle.modelOfVehicle}");
  53. Console.WriteLine($"Color: {vehicle.colorOfVehicle}");
  54. Console.WriteLine($"Horsepower: {vehicle.horsepowerOfVehicle}");
  55. }
  56. if (countCars>0)
  57. {
  58. Console.WriteLine($"Cars have average horsepower of: {sumCars / countCars:f2}.");
  59. }
  60. if (countTrucks>0)
  61. {
  62. Console.WriteLine($"Trucks have average horsepower of: {sumTrucks / countTrucks:f2}.");
  63. }
  64.  
  65. }
  66. }
  67.  
  68. class Vehicle
  69. {
  70. public string typeOfVehicle;
  71. public string modelOfVehicle;
  72. public string colorOfVehicle;
  73. public int horsepowerOfVehicle;
  74.  
  75. public Vehicle(string type,string model, string color,int hp)
  76. {
  77. this.typeOfVehicle = type;
  78. this.modelOfVehicle = model;
  79. this.colorOfVehicle = color;
  80. this.horsepowerOfVehicle = hp;
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment