TheBulgarianWolf

Vehicle Catalogue

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