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 Vehicle_Catalog
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> command = Console.ReadLine().ToLower().Split().ToList();
- List<dynamic> list = new List<dynamic>();
- var carAvHp = 0.0;
- var truckAvHp = 0.0;
- var carCounter = 0;
- var truckCounter = 0;
- var carHp = 0.0;
- var truckHp = 0.0;
- while (command[0] != "end")
- {
- string type = command[0].ToString();
- string model = command[1].ToString();
- string color = command[2].ToString();
- int hp = int.Parse(command[3]);
- dynamic catalog = new { type, model, color, hp };
- list.Add(catalog);
- command = Console.ReadLine().ToLower().Split().ToList();
- }
- foreach (var mps in list)
- {
- if (mps.type == "car")
- {
- carCounter++;
- carHp += mps.hp;
- }
- if (mps.type == "truck")
- {
- truckCounter++;
- truckHp += mps.hp;
- }
- }
- carAvHp = carHp / carCounter;
- truckAvHp = truckHp / truckCounter;
- string searchCommand = Console.ReadLine().ToLower();
- while (searchCommand != "close the catalog")
- {
- searchCommand.Split().ToList();
- foreach (var item in list)
- {
- if (item.model == searchCommand[0])
- {
- Console.WriteLine($"Type: {item.type}");
- Console.WriteLine($"Model: {item.model}");
- Console.WriteLine($"Color: {item.color}");
- Console.WriteLine($"Horsepower: {item.hp}");
- }
- }
- searchCommand = Console.ReadLine().ToLower();
- }
- Console.WriteLine($"Cars have average horsepower of: {carAvHp:f2}.");
- Console.WriteLine($"Trucks have average horsepower of: {truckAvHp:f2}.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement