Advertisement
Guest User

Untitled

a guest
Mar 11th, 2020
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _08_Lab_Vehicle_Catalogue
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string command = Console.ReadLine();
  12.  
  13. var catalog = new Catalog();
  14. catalog.trucks = new List<Truck>();
  15. catalog.cars = new List<Car>();
  16.  
  17. while (command!="end")
  18. {
  19. string[] commandArr = command.Split("/");
  20. string type = commandArr[0];
  21.  
  22. if (type=="Car")
  23. {
  24.  
  25. catalog.cars.Add(new Car(commandArr));
  26. }
  27.  
  28. else if (type=="Truck")
  29. {
  30. catalog.trucks.Add(new Truck (commandArr));
  31. }
  32.  
  33.  
  34. command = Console.ReadLine();
  35. }
  36.  
  37. if (catalog.cars.Count > 0)
  38. {
  39. Console.WriteLine("Cars:");
  40. foreach (var car in catalog.cars.OrderBy(x=>x.Brand))
  41. {
  42. Console.WriteLine($"{car.Brand}: {car.Model} - {car.HorsePower}hp");
  43. }
  44. }
  45. if (catalog.trucks.Count > 0)
  46. {
  47. Console.WriteLine("Trucks:");
  48. foreach (var truck in catalog.trucks.OrderBy(y=>y.Brand))
  49. {
  50. Console.WriteLine($"{truck.Brand}: {truck.Model} - {truck.Weight}kg");
  51. }
  52. }
  53.  
  54. }
  55. }
  56.  
  57. class Catalog
  58. {
  59. public List<Truck> trucks;
  60. public List<Car> cars;
  61. }
  62.  
  63. class Truck
  64. {
  65. public string Brand { get; set; }
  66. public string Model { get; set; }
  67. public string Weight { get; set; }
  68.  
  69. public Truck (string[]commandArr)
  70. {
  71. string brand = commandArr[1];
  72. string model = commandArr[2];
  73. string weight = commandArr[3];
  74.  
  75. Brand = brand;
  76. Model = model;
  77. Weight = weight;
  78. }
  79. }
  80.  
  81. class Car
  82. {
  83. public string Brand { get; set; }
  84. public string Model { get; set; }
  85. public string HorsePower { get; set; }
  86.  
  87. public Car (string[]commandArr)
  88. {
  89. string brand = commandArr[1];
  90. string model = commandArr[2];
  91. string horsePower = commandArr[3];
  92.  
  93. Brand = brand;
  94. Model = model;
  95. HorsePower = horsePower;
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement