Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Problem06VehicleCatalogue
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Car> cars = new List<Car>();
- List<Truck> trucks = new List<Truck>();
- int numberOfCars = 0;
- int numberOfTrucks = 0;
- double horsePowerCars = 0;
- double horsePowerTrucks = 0;
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "End") break;
- string[] inputAsArray = command.Split();
- string typeOfVehicle = inputAsArray[0];
- string model = inputAsArray[1];
- string color = inputAsArray[2];
- int horsePower = int.Parse(inputAsArray[3]);
- if (typeOfVehicle == "car")
- {
- Car newCar = new Car()
- {
- Model = model,
- Color = color,
- HorsePower = horsePower
- };
- numberOfCars += 1;
- horsePowerCars += horsePower;
- cars.Add(newCar);
- }
- else
- {
- Truck newTruck = new Truck()
- {
- Model = model,
- Color = color,
- HorsePower = horsePower
- };
- numberOfTrucks += 1;
- horsePowerTrucks += horsePower;
- trucks.Add(newTruck);
- }
- }
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "Close the Catalogue")
- {
- break;
- }
- string model = command;
- foreach (var car in cars)
- {
- if (car.Model == model)
- {
- //Type: {typeOfVehicle}
- //Model: {modelOfVehicle}
- //Color: {colorOfVehicle}
- //Horsepower: {horsepowerOfVehicle}
- Console.WriteLine($"Type: Car");
- Console.WriteLine($"Model: {car.Model}");
- Console.WriteLine($"Color: {car.Color}");
- Console.WriteLine($"Horsepower: {car.HorsePower}");
- break;
- }
- }
- foreach (var truck in trucks)
- {
- if (truck.Model == model)
- {
- //Type: {typeOfVehicle}
- //Model: {modelOfVehicle}
- //Color: {colorOfVehicle}
- //Horsepower: {horsepowerOfVehicle}
- Console.WriteLine($"Type: Truck");
- Console.WriteLine($"Model: {truck.Model}");
- Console.WriteLine($"Color: {truck.Color}");
- Console.WriteLine($"Horsepower: {truck.HorsePower}");
- break;
- }
- }
- }
- Console.WriteLine($"Cars have average horsepower of: {(horsePowerCars / numberOfCars):F2}.");
- Console.WriteLine($"Trucks have average horsepower of: {(horsePowerTrucks / numberOfTrucks):F2}.");
- }
- }
- class Car
- {
- public string Model;
- public string Color;
- public int HorsePower;
- }
- class Truck
- {
- public string Model;
- public string Color;
- public int HorsePower;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement