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