Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _06_VehicleCatalogue
- {
- public class Vehicle
- {
- public Vehicle(string typeOfVehicle, string model, string color, int horespower)
- {
- this.TypeOfVehicle = typeOfVehicle;
- this.Model = model;
- this.Color = color;
- this.Horsepower = horespower;
- }
- public string TypeOfVehicle { get; set; }
- public string Model { get; set; }
- public string Color { get; set; }
- public int Horsepower { get; set; }
- public override string ToString()
- {
- return $"Type: {this.TypeOfVehicle} {Environment.NewLine}Model: {this.Model} {Environment.NewLine}Color: {this.Color} {Environment.NewLine}Horsepower: {this.Horsepower}";
- }
- }
- public class Program
- {
- public static void Main()
- {
- var listOfVehicles = new List<Vehicle>();
- var cars = new List<Vehicle>();
- var trucks = new List<Vehicle>();
- while (true)
- {
- var input = Console.ReadLine();
- if (input == "End")
- {
- break;
- }
- var splittedInput = input
- .Split()
- .ToList();
- var type = splittedInput[0];
- var model = splittedInput[1];
- var color = splittedInput[2];
- var horsepower = int.Parse(splittedInput[3]);
- var vehicle = new Vehicle(type, model, color, horsepower);
- listOfVehicles.Add(vehicle);
- if (type == "car")
- {
- cars.Add(vehicle);
- }
- else if (type == "truck")
- {
- trucks.Add(vehicle);
- }
- }
- while (true)
- {
- var modelInput = Console.ReadLine();
- if (modelInput == "Close the Catalogue")
- {
- break;
- }
- var vehicle = listOfVehicles
- .Where(x => x.Model == modelInput)
- .First();
- Console.WriteLine(vehicle);
- }
- if (cars.Count > 0)
- {
- Console.WriteLine($"Cars have average horsepower of: {cars.Select(x=>x.Horsepower).Average():f2}");
- }
- else
- {
- Console.WriteLine("Cars have average horsepower of: 0.00");
- }
- if (trucks.Count > 0)
- {
- Console.WriteLine($"Trucks have average horsepower of: {trucks.Select(x => x.Horsepower).Average():f2}");
- }
- else
- {
- Console.WriteLine($"Trucks have average horsepower of: 0.00");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement