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