Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Vehicle_Catalogue
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Vehicle> autos = new List<Vehicle>();
- string input = string.Empty;
- double truckHorsePower = 0;
- int counterTruck = 0;
- double carHorsePower = 0;
- int counterCar = 0;
- while ((input=Console.ReadLine())!="End")
- {
- string[] data = input.Split(' ');
- Vehicle currAuto = new Vehicle(data[0], data[1], data[2], int.Parse(data[3]));
- if (data[0]=="truck")
- {
- currAuto.Type="Truck";
- truckHorsePower += currAuto.Horsepower;
- counterTruck++;
- }
- else
- {
- currAuto.Type = "Car";
- carHorsePower += currAuto.Horsepower;
- counterCar++;
- }
- autos.Add(currAuto);
- }
- string currModel = string.Empty;
- while ((currModel = Console.ReadLine()) != "Close the Catalogue")
- {
- foreach (Vehicle auto in autos)
- {
- if (auto.Model == currModel)
- {
- Console.WriteLine($"Type: {auto.Type}");
- Console.WriteLine($"Model: {auto.Model}");
- Console.WriteLine($"Color: {auto.Color}");
- Console.WriteLine($"Horsepower: {auto.Horsepower}");
- }
- }
- }
- double midCarHorsePower = carHorsePower / counterCar;
- double midTruckHorsePower = truckHorsePower / counterTruck;
- Console.WriteLine($"Cars have average horsepower of: { midCarHorsePower:F2}.");
- Console.WriteLine($"Trucks have average horsepower of: { midTruckHorsePower:F2}.");
- }
- }
- 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; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement