static void Main(string[] args) { List <Car> cars = new List <Car>(); List <Truck> trucks = new List <Truck>(); while (true) { string line = Console.ReadLine(); if (line == "end") { break; } string[] tokens = line.Split("/"); string type = tokens[0]; string brand = tokens[1]; string model = tokens[2]; int horsePowerOrWeight = int.Parse(tokens[3]); if (type == "Car") { Car currentCar = new Car(brand, model, horsePowerOrWeight); cars.Add(currentCar); } else { Truck currentTruck = new Truck(brand, model, horsePowerOrWeight); trucks.Add(currentTruck); } } CatalogueVehicle catalogue = new CatalogueVehicle(cars, trucks); if (cars.Count != 0) { Console.WriteLine("Cars:"); foreach (var car in catalogue.CarsCollection.OrderBy(x => x.Brand)) { Console.WriteLine($"{car.Brand}: {car.Model} - {car.HorsePower}hp"); } } if (trucks.Count != 0) { Console.WriteLine("Trucks:"); foreach (var truck in catalogue.TrucksCollection.OrderBy(x => x.Brand)) { Console.WriteLine($"{truck.Brand}: {truck.Model} - {truck.Weight}kg"); } } }
static void Main(string[] args) { Console.WriteLine("Start entering vehicles in the following format({type}/{brand}/{model}/{horse power / weight}): "); string input; CatalogueVehicle catalogueVehicle = new CatalogueVehicle(); while ((input = Console.ReadLine()) != "end") { string[] inputInfo = input.Split("/"); string type = inputInfo[0]; string brand = inputInfo[1]; string model = inputInfo[2]; int lastSpec = int.Parse(inputInfo[3]); if (type == "Car") { Car car = new Car(brand, model, lastSpec); catalogueVehicle.cars.Add(car); } else if (type == "Truck") { Truck truck = new Truck(brand, model, lastSpec); catalogueVehicle.trucks.Add(truck); } } Console.WriteLine("Cars: "); foreach (Car car in catalogueVehicle.cars) { Console.WriteLine($"{car.Brand}: {car.Model} - {car.HorsePower}hp."); } Console.WriteLine(); Console.WriteLine("Trucks: "); foreach (Truck truck in catalogueVehicle.trucks) { Console.WriteLine($"{truck.Brand}: {truck.Model} - {truck.Weight}kgs."); } }