kvadrat4o

VehicleCatalogue

Jun 27th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Globalization;
  7.  
  8. namespace Vehicle_Catalogue
  9. {
  10.     public class Vehicle
  11.     {
  12.         public string Type { get; set; }
  13.         public string Model { get; set; }
  14.         public string Color { get; set; }
  15.         public decimal Horses { get; set; }
  16.         public decimal Averages { get; set; }
  17.  
  18.         static void Main(string[] args)
  19.         {
  20.             decimal truckAvg = 0.00M;
  21.             var carAvg = 0.00M;
  22.             var vehicles = new List<Vehicle>();
  23.             var trucks = new List<Vehicle>();
  24.             var cars = new List<Vehicle>();
  25.             var inputString = Console.ReadLine().Split(' ');
  26.             var command = inputString[0];
  27.             while (command != "End")
  28.             {
  29.                 var currentVehicle = new Vehicle
  30.                 {
  31.                     Type = inputString[0],
  32.                     Model = inputString[1],
  33.                     Color = inputString[2],
  34.                     Horses = decimal.Parse(inputString[3])
  35.                 };
  36.                 vehicles.Add(currentVehicle);
  37.                 if (command == "Close the Catalogue")
  38.                 {
  39.                     trucks = vehicles.Where(a => a.Type == "truck" || a.Type == "Truck").OrderBy(a => a.Type).ThenBy(a => a.Model).ToList();
  40.                     truckAvg = trucks.Sum(a => a.Horses) / trucks.Count;
  41.                     cars = vehicles.Where(b => b.Type == "car" || b.Type == "Car").OrderBy(a => a.Type).ThenBy(a => a.Model).ToList();
  42.                     carAvg = cars.Sum(b => b.Horses) / cars.Count;
  43.                     foreach (var car in cars)
  44.                     {
  45.                         Console.WriteLine("Cars have average horsepower of {0:F2}.", carAvg);
  46.                     }
  47.                     foreach (var truck in trucks)
  48.                     {
  49.                         Console.WriteLine("Trucks have average horsepower of {0:F2}.",truckAvg);
  50.                     }
  51.                 }
  52.                 inputString = Console.ReadLine().Split(' ');
  53.                 command = inputString[0];
  54.             }
  55.             foreach (var vehicle in vehicles)
  56.             {
  57.                 vehicles = vehicles.OrderBy(a => a.Type).ThenBy(a => a.Model).ToList();
  58.                 Console.WriteLine(string.Format("Type: {0}\nModel: {1}\nColor: {2}\nHorsepower: {3}", vehicle.Type, vehicle.Model, vehicle.Color, vehicle.Horses));
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment