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;
- using System.Globalization;
- namespace Vehicle_Catalogue
- {
- public class Vehicle
- {
- public string Type { get; set; }
- public string Model { get; set; }
- public string Color { get; set; }
- public decimal Horses { get; set; }
- public decimal Averages { get; set; }
- static void Main(string[] args)
- {
- decimal truckAvg = 0.00M;
- var carAvg = 0.00M;
- var vehicles = new List<Vehicle>();
- var trucks = new List<Vehicle>();
- var cars = new List<Vehicle>();
- var inputString = Console.ReadLine().Split(' ');
- var command = inputString[0];
- while (command != "End")
- {
- var currentVehicle = new Vehicle
- {
- Type = inputString[0],
- Model = inputString[1],
- Color = inputString[2],
- Horses = decimal.Parse(inputString[3])
- };
- vehicles.Add(currentVehicle);
- if (command == "Close the Catalogue")
- {
- trucks = vehicles.Where(a => a.Type == "truck" || a.Type == "Truck").OrderBy(a => a.Type).ThenBy(a => a.Model).ToList();
- truckAvg = trucks.Sum(a => a.Horses) / trucks.Count;
- cars = vehicles.Where(b => b.Type == "car" || b.Type == "Car").OrderBy(a => a.Type).ThenBy(a => a.Model).ToList();
- carAvg = cars.Sum(b => b.Horses) / cars.Count;
- foreach (var car in cars)
- {
- Console.WriteLine("Cars have average horsepower of {0:F2}.", carAvg);
- }
- foreach (var truck in trucks)
- {
- Console.WriteLine("Trucks have average horsepower of {0:F2}.",truckAvg);
- }
- }
- inputString = Console.ReadLine().Split(' ');
- command = inputString[0];
- }
- foreach (var vehicle in vehicles)
- {
- vehicles = vehicles.OrderBy(a => a.Type).ThenBy(a => a.Model).ToList();
- Console.WriteLine(string.Format("Type: {0}\nModel: {1}\nColor: {2}\nHorsepower: {3}", vehicle.Type, vehicle.Model, vehicle.Color, vehicle.Horses));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment