Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Numerics;
- namespace ConsoleApp7
- {
- class Program
- {
- static void Main()
- {
- List<Vehicle> Vehicles = new List<Vehicle>();
- List<Vehicle> vehiclesPrint = new List<Vehicle>();
- double sumCars=0;
- int countCars=0;
- double sumTrucks = 0;
- int countTrucks = 0;
- string input01;
- while ((input01=Console.ReadLine())!="End")
- {
- string[] inputData = input01.Split(' ');
- Vehicle vehicle01 = new Vehicle(inputData[0], inputData[1], inputData[2], int.Parse(inputData[3]));
- Vehicles.Add(vehicle01);
- if (inputData[0]=="car")
- {
- sumCars += int.Parse(inputData[3]);
- countCars++;
- }else if (inputData[0] == "truck")
- {
- sumTrucks +=int.Parse(inputData[3]);
- countTrucks++;
- }
- }
- string input02;
- while ((input02 = Console.ReadLine()) != "Close the Catalogue")
- {
- if (Vehicles.Any(x=>x.modelOfVehicle==input02))
- {
- vehiclesPrint.Add(Vehicles.First(x => x.modelOfVehicle == input02));
- }
- }
- foreach (Vehicle vehicle in vehiclesPrint)
- {
- string capitalizedString = char.ToUpper(vehicle.typeOfVehicle[0]) + vehicle.typeOfVehicle.Substring(1);
- Console.WriteLine($"Type: {capitalizedString}");
- Console.WriteLine($"Model: {vehicle.modelOfVehicle}");
- Console.WriteLine($"Color: {vehicle.colorOfVehicle}");
- Console.WriteLine($"Horsepower: {vehicle.horsepowerOfVehicle}");
- }
- if (countCars>0)
- {
- Console.WriteLine($"Cars have average horsepower of: {sumCars / countCars:f2}.");
- }
- if (countTrucks>0)
- {
- Console.WriteLine($"Trucks have average horsepower of: {sumTrucks / countTrucks:f2}.");
- }
- }
- }
- class Vehicle
- {
- public string typeOfVehicle;
- public string modelOfVehicle;
- public string colorOfVehicle;
- public int horsepowerOfVehicle;
- public Vehicle(string type,string model, string color,int hp)
- {
- this.typeOfVehicle = type;
- this.modelOfVehicle = model;
- this.colorOfVehicle = color;
- this.horsepowerOfVehicle = hp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment