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