Advertisement
silvana1303

vehicle catalog

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