osman1997

ObjAndClasses

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