TheBulgarianWolf

Vehicle Catalogue 2.0

Jan 7th, 2021
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace VehicleCatalogue2._0
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             List<Car> cars = new List<Car>();
  11.             List<Truck> trucks = new List<Truck>();
  12.             //{typeOfVehicle} {model} {color} {horsepower}
  13.             Console.WriteLine("Start entering specifications: ");
  14.             string input;
  15.             while ((input = Console.ReadLine()) != "End")
  16.             {
  17.                 string[] inputInfo = input.Split(" ");
  18.                 string type = inputInfo[0];
  19.                 string brand = inputInfo[1];
  20.                 string color = inputInfo[2];
  21.                 int hp = int.Parse(inputInfo[3]);
  22.  
  23.                 if (type == "car")
  24.                 {
  25.                     Car car = new Car(brand, color, hp);
  26.                     cars.Add(car);
  27.                 }
  28.                 else if (type == "truck")
  29.                 {
  30.                     Truck truck = new Truck(brand, color, hp);
  31.                     trucks.Add(truck);
  32.                 }
  33.  
  34.             }
  35.  
  36.             Console.WriteLine("Enter a car/truck brand: ");
  37.             while ((input = Console.ReadLine()) != "Close The Catalogue")
  38.             {
  39.                 string brand = input;
  40.                 foreach (Car car in cars)
  41.                 {
  42.                     if (car.Brand == brand)
  43.                     {
  44.                         Console.WriteLine("Type: Car");
  45.                         Console.WriteLine("Model: " + car.Brand);
  46.                         Console.WriteLine("Color: " + car.Color);
  47.                         Console.WriteLine("Horse Power: " + car.HorsePower);
  48.                     }
  49.                 }
  50.  
  51.                 foreach (Truck truck in trucks)
  52.                 {
  53.                     if (truck.Brand == brand)
  54.                     {
  55.                         Console.WriteLine("Type: Truck");
  56.                         Console.WriteLine("Model: " + truck.Brand);
  57.                         Console.WriteLine("Color: " + truck.Color);
  58.                         Console.WriteLine("Horse Power: " + truck.HorsePower);
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.  
  64.         class Car
  65.         {
  66.             public Car(string brand, string color, int horsePower)
  67.             {
  68.                 Brand = brand;
  69.                 Color = color;
  70.                 HorsePower = horsePower;
  71.             }
  72.  
  73.             public string Brand { get; set; }
  74.             public string Color { get; set; }
  75.             public int HorsePower { get; set; }
  76.  
  77.         }
  78.  
  79.         class Truck
  80.         {
  81.             public Truck(string brand, string color, int horsePower)
  82.             {
  83.                 Brand = brand;
  84.                 Color = color;
  85.                 HorsePower = horsePower;
  86.             }
  87.  
  88.             public string Brand { get; set; }
  89.             public string Color { get; set; }
  90.             public int HorsePower { get; set; }
  91.  
  92.         }
  93.     }
  94. }
Add Comment
Please, Sign In to add comment