Advertisement
Katina_

Vehicle_Catalogue

Jun 26th, 2019
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. //Class
  6. namespace VehicleCatalogue
  7. {
  8.     class Catalogue
  9.     {
  10.  
  11.         public string Type { get; set; }
  12.         public string Brand { get; set; }
  13.         public string Model { get; set; }
  14.         public double Weight { get; set; }
  15.         public double HorsePower { get; set; }
  16.     }
  17. }
  18.  
  19. //Main
  20. namespace VehicleCatalogue
  21. {
  22.     class Program
  23.     {
  24.         static void Main(string[] args)
  25.         {
  26.             List<Catalogue> vehicleCatalogue = new List<Catalogue>();
  27.             int count = 0;
  28.  
  29.             while (true)
  30.             {
  31.                 string command = Console.ReadLine();
  32.                 string[] parts = command.Split("/");
  33.  
  34.                 if (command == "end")
  35.                 {
  36.                     break;
  37.                 }
  38.  
  39.                 string type = parts[0];
  40.                 string brand = parts[1];
  41.                 string model = parts[2];
  42.                 double weight = double.Parse(parts[3]);
  43.                 double horsePower = double.Parse(parts[3]);
  44.  
  45.                 Catalogue vehicle = new Catalogue();
  46.  
  47.                 vehicle.Type = type;
  48.                 vehicle.Brand = brand;
  49.                 vehicle.Model = model;
  50.                 vehicle.Weight = weight;
  51.                 vehicle.HorsePower = horsePower;
  52.  
  53.                 vehicleCatalogue.Add(vehicle);
  54.                
  55.             }
  56.  
  57.             List<Catalogue> sortedCatalogue = vehicleCatalogue.OrderBy(vehicle => vehicle.Brand).ToList();
  58.  
  59.             foreach (Catalogue vehicle in sortedCatalogue)
  60.             {
  61.                 if (count == 0)
  62.                 {
  63.                     Console.WriteLine("Cars:");
  64.                     count++;
  65.                 }
  66.  
  67.                 if(vehicle.Type == "Car")
  68.                 {
  69.                     Console.WriteLine($"{vehicle.Brand}: {vehicle.Model} - {vehicle.HorsePower}hp");
  70.                 }
  71.             }
  72.  
  73.             foreach (Catalogue vehicle in sortedCatalogue)
  74.             {
  75.                 if (count == 1 && vehicle.Type == "Truck")
  76.                 {
  77.                     Console.WriteLine("Trucks:");
  78.                     count++;
  79.                 }
  80.  
  81.                 if (vehicle.Type == "Truck")
  82.                 {
  83.                     Console.WriteLine($"{vehicle.Brand}: {vehicle.Model} - {vehicle.Weight}kg");
  84.                 }
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement