Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Channels;
- namespace VehicleCatalogue
- {
- class Vehicle
- {
- public Vehicle(string type, string model, string color, int horsepower)
- {
- this.Type = type;
- this.Model = model;
- this.Color = color;
- this.Horsepower = horsepower;
- }
- public string Type { get; set; }
- public string Model { get; set; }
- public string Color { get; set; }
- public int Horsepower { get; set; }
- }
- class Program
- {
- public static void Main()
- {
- List<Vehicle> vehicles = new List<Vehicle>();
- string command;
- while ((command = Console.ReadLine()) != "End")
- {
- string[] info = command.Split(" ");
- string type = info[0];
- string model = info[1];
- string color = info[2];
- string horsepower = info[3];
- vehicles.Add(new Vehicle(type, model, color, int.Parse(horsepower)));
- }
- while ((command = Console.ReadLine()) != "Close the Catalogue")
- {
- int index = IndexFinder(vehicles, command);
- string type = vehicles[index].Type;
- Console.WriteLine($"Type: {type[0].ToString().ToUpper() + type.Substring(1)}\nModel: {vehicles[index].Model}\nColor: {vehicles[index].Color}\nHorsepower: {vehicles[index].Horsepower}");
- }
- var cars = vehicles.Where(x => x.Type == "car");
- var trucks = vehicles.Where(x => x.Type == "truck");
- double carsHorsepower = cars.Count() > 0 ? (double)(cars.Select(x => x.Horsepower).ToList().Sum()) / cars.Count() : 0;
- double trucksHorsepower = trucks.Count() > 0 ? (double)(trucks.Select(x => x.Horsepower).ToList().Sum()) / trucks.Count() : 0;
- Console.WriteLine($"Cars have average horsepower of: {carsHorsepower:f2}.");
- Console.WriteLine($"Trucks have average horsepower of: {trucksHorsepower:f2}.");
- }
- static int IndexFinder(List<Vehicle> v, string m)
- {
- return v.FindIndex(x => x.Model == m);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement