Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 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.  
  7. namespace Vehicle_Catalog
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> command = Console.ReadLine().ToLower().Split().ToList();
  14.             List<dynamic> list = new List<dynamic>();
  15.             var carAvHp = 0.0;
  16.             var truckAvHp = 0.0;
  17.             var carCounter = 0;
  18.             var truckCounter = 0;
  19.             var carHp = 0.0;
  20.             var truckHp = 0.0;
  21.             while (command[0] != "end")
  22.             {
  23.                 string type = command[0].ToString();
  24.                 string model = command[1].ToString();
  25.                 string color = command[2].ToString();
  26.                 int hp = int.Parse(command[3]);
  27.                 dynamic catalog = new { type, model, color, hp };
  28.                 list.Add(catalog);
  29.                 command = Console.ReadLine().ToLower().Split().ToList();
  30.             }
  31.             foreach (var mps in list)
  32.             {
  33.                 if (mps.type == "car")
  34.                 {
  35.                     carCounter++;
  36.                     carHp += mps.hp;
  37.                 }
  38.                 if (mps.type == "truck")
  39.                 {
  40.                     truckCounter++;
  41.                     truckHp += mps.hp;
  42.                 }
  43.             }
  44.             carAvHp = carHp / carCounter;
  45.             truckAvHp = truckHp / truckCounter;
  46.             string searchCommand = Console.ReadLine().ToLower();
  47.             while (searchCommand  != "close the catalog")
  48.             {
  49.                 searchCommand.Split().ToList();                
  50.                 foreach (var item in list)
  51.                 {
  52.                     if (item.model == searchCommand[0])
  53.                     {
  54.                         Console.WriteLine($"Type: {item.type}");
  55.                         Console.WriteLine($"Model: {item.model}");
  56.                         Console.WriteLine($"Color: {item.color}");
  57.                         Console.WriteLine($"Horsepower: {item.hp}");
  58.                     }
  59.                 }
  60.                 searchCommand = Console.ReadLine().ToLower();
  61.             }
  62.             Console.WriteLine($"Cars have average horsepower of: {carAvHp:f2}.");
  63.             Console.WriteLine($"Trucks have average horsepower of: {truckAvHp:f2}.");
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement