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.Tasks;
- namespace VehicleCatalogue
- {
- public class Vehicles
- {
- public static string FirstCharToUpper(string input)
- {
- if (String.IsNullOrEmpty(input))
- throw new ArgumentException("ARGH!");
- return input.First().ToString().ToUpper() + input.Substring(1);
- }
- public string Type { get; set; }
- public string Model { get; set; }
- public string Color { get; set; }
- public int Horsepower { get; set; }
- public Vehicles(string type, string model, string color, int horsepower)
- {
- this.Type = type;
- this.Model = model;
- this.Color = color;
- this.Horsepower = horsepower;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<Vehicles> car = new List<Vehicles>();
- List<Vehicles> truck = new List<Vehicles>();
- while (true)
- {
- List<string> inPut = Console.ReadLine()
- .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- if(inPut[0] == "End")
- {
- break;
- }
- string type = inPut[0];
- string model = inPut[1];
- string color = inPut[2];
- int horsepower = int.Parse(inPut[3]);
- Vehicles sortedVehicles = new Vehicles(type, model, color, horsepower);
- if(type == "car" || type == "Car")
- {
- car.Add(sortedVehicles);
- }
- if (type == "truck" || type == "Truck")
- {
- truck.Add(sortedVehicles);
- }
- }
- while (true)
- {
- List<string> modelsOfVehicles = Console.ReadLine()
- .Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- if(modelsOfVehicles[0] == "Close the Catalogue")
- {
- break;
- }
- string findModel = modelsOfVehicles[0];
- foreach (var item in car)
- {
- if (item.Model == findModel)
- {
- Console.WriteLine("Type: " + Vehicles.FirstCharToUpper(item.Type));
- Console.WriteLine("Model: " + item.Model);
- Console.WriteLine("Color: " + item.Color);
- Console.WriteLine("Horsepower: " + item.Horsepower);
- break;
- }
- }
- foreach (var item in truck)
- {
- if (item.Model == findModel)
- {
- Console.WriteLine("Type: " + char.ToUpper(item.Type[0]) + item.Type.Substring(1));
- Console.WriteLine("Model: " + item.Model);
- Console.WriteLine("Color: " + item.Color);
- Console.WriteLine("Horsepower: " + item.Horsepower);
- }
- }
- }
- double sumCar = car.Average(x=>x.Horsepower);
- double sumTruck = truck.Average(x => x.Horsepower);
- if (car.Count > 0)
- {
- Console.WriteLine($"Cars have average horsepower of: {sumCar:f2}.");
- }
- else
- {
- Console.WriteLine($"Cars have average horsepower of: {0:f2}.");
- }
- if (truck.Count > 0)
- {
- Console.WriteLine($"Trucks have average horsepower of: {sumTruck:f2}.");
- }
- else
- {
- Console.WriteLine($"Trucks have average horsepower of: {0:f2}.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement