Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _08_Lab_Vehicle_Catalogue
- {
- class Program
- {
- static void Main(string[] args)
- {
- string command = Console.ReadLine();
- var catalog = new Catalog();
- catalog.trucks = new List<Truck>();
- catalog.cars = new List<Car>();
- while (command!="end")
- {
- string[] commandArr = command.Split("/");
- string type = commandArr[0];
- if (type=="Car")
- {
- catalog.cars.Add(new Car(commandArr));
- }
- else if (type=="Truck")
- {
- catalog.trucks.Add(new Truck (commandArr));
- }
- command = Console.ReadLine();
- }
- if (catalog.cars.Count > 0)
- {
- Console.WriteLine("Cars:");
- foreach (var car in catalog.cars.OrderBy(x=>x.Brand))
- {
- Console.WriteLine($"{car.Brand}: {car.Model} - {car.HorsePower}hp");
- }
- }
- if (catalog.trucks.Count > 0)
- {
- Console.WriteLine("Trucks:");
- foreach (var truck in catalog.trucks.OrderBy(y=>y.Brand))
- {
- Console.WriteLine($"{truck.Brand}: {truck.Model} - {truck.Weight}kg");
- }
- }
- }
- }
- class Catalog
- {
- public List<Truck> trucks;
- public List<Car> cars;
- }
- class Truck
- {
- public string Brand { get; set; }
- public string Model { get; set; }
- public string Weight { get; set; }
- public Truck (string[]commandArr)
- {
- string brand = commandArr[1];
- string model = commandArr[2];
- string weight = commandArr[3];
- Brand = brand;
- Model = model;
- Weight = weight;
- }
- }
- class Car
- {
- public string Brand { get; set; }
- public string Model { get; set; }
- public string HorsePower { get; set; }
- public Car (string[]commandArr)
- {
- string brand = commandArr[1];
- string model = commandArr[2];
- string horsePower = commandArr[3];
- Brand = brand;
- Model = model;
- HorsePower = horsePower;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement