Advertisement
svetlyoek

Untitled

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