Advertisement
nikolapetkov824

VehicleCatalogue

Nov 10th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace PracticeCuzIAmPleb
  6. {
  7.     public class Truck
  8.     {
  9.         public string Brand { get; set; }
  10.         public string Model { get; set; }
  11.         public int Weight { get; set; }
  12.  
  13.         public Truck(string brand
  14.             , string model
  15.             , int weight)
  16.         {
  17.             this.Brand = brand;
  18.             this.Model = model;
  19.             this.Weight = weight;
  20.         }
  21.     }
  22.  
  23.     public class Car
  24.     {
  25.         public string Brand { get; set; }
  26.         public string Model { get; set; }
  27.         public int HorsePower { get; set; }
  28.  
  29.         public Car(string brand
  30.             , string model
  31.             , int horsePower)
  32.         {
  33.             this.Brand = brand;
  34.             this.Model = model;
  35.             this.HorsePower = horsePower;
  36.         }
  37.     }
  38.  
  39.     public class CatalogVehicle
  40.     {
  41.         public List<Truck> TruckCatalog  { get; set; }
  42.  
  43.         public List<Car> CarCatalog { get; set; }
  44.  
  45.         public CatalogVehicle(List<Car> cars, List<Truck> trucks)
  46.         {
  47.             this.CarCatalog = cars;
  48.             this.TruckCatalog = trucks;
  49.         }
  50.     }
  51.  
  52.     class Program
  53.     {
  54.         static void Main(string[] args)
  55.         {
  56.             List<Truck> truckInfo = new List<Truck>();
  57.             List<Car> carInfo = new List<Car>();
  58.  
  59.             string input = Console.ReadLine();
  60.  
  61.             while (input != "end")
  62.             {
  63.                 string[] data = input.Split('/');
  64.  
  65.                 string vehicleType = data[0];
  66.                 string carName = data[1];
  67.                 string model = data[2];
  68.                 int additionalInfo = int.Parse(data[3]);
  69.  
  70.                 if (vehicleType == "Car")
  71.                 {
  72.                     Car car = new Car(carName, model, additionalInfo)
  73.                     {
  74.                         Brand = carName,
  75.                         Model = model,
  76.                         HorsePower = additionalInfo
  77.                     };
  78.  
  79.                     carInfo.Add(car);
  80.                 }
  81.                 else
  82.                 {
  83.                     Truck truck = new Truck(carName, model, additionalInfo)
  84.                     {
  85.                         Brand = carName,
  86.                         Model = model,
  87.                         Weight = additionalInfo
  88.                     };
  89.  
  90.                     truckInfo.Add(truck);
  91.                 }
  92.  
  93.                 input = Console.ReadLine();
  94.             }
  95.  
  96.             CatalogVehicle resultInfo = new CatalogVehicle(carInfo, truckInfo);
  97.            
  98.             if (carInfo.Count>0)
  99.             {
  100.                 Console.WriteLine("Cars:");
  101.                
  102.                 foreach (var car in resultInfo.CarCatalog.OrderBy(x => x.Brand))
  103.                 {
  104.                     Console.WriteLine($"{car.Brand}: {car.Model} - {car.HorsePower}hp");
  105.                 }
  106.  
  107.             }
  108.  
  109.             if (truckInfo.Count>0)
  110.             {
  111.                 Console.WriteLine("Trucks:");
  112.                
  113.                 foreach (var truck in resultInfo.TruckCatalog.OrderBy(x => x.Brand))
  114.                 {
  115.                     Console.WriteLine($"{truck.Brand}: {truck.Model} - {truck.Weight}kg");
  116.                 }
  117.             }
  118.            
  119.         }
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement