TheBulgarianWolf

Raw Data

Jan 16th, 2021
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace RawData
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<Car> cars = new List<Car>();
  12.             Console.WriteLine("Enter the number of cars you are about to enter: ");
  13.             int number = int.Parse(Console.ReadLine());
  14.             for (int i = 0; i < number; i++)
  15.             {
  16.                 string[] carInfo = Console.ReadLine().Split(" ");
  17.                 cars.Add(new Car(carInfo));
  18.             }
  19.             Console.WriteLine("Enter type of cargo: ");
  20.             string type = Console.ReadLine();
  21.             if(type == "flamable")
  22.             {
  23.                 foreach(var car in cars.Where(c => c.Cargo.Type == "flamable" && c.Engine.Power > 250))
  24.                 {
  25.                     Console.WriteLine($"{car.Model}");
  26.                 }
  27.             }
  28.             else if(type == "fragile")
  29.             {
  30.                 foreach (var car in cars.Where(c => c.Cargo.Type == "fragile" && c.Cargo.Weight<1000))
  31.                 {
  32.                     Console.WriteLine($"{car.Model}");
  33.                 }
  34.             }
  35.         }
  36.     }
  37.  
  38.     class Car
  39.     {
  40.         public string Model { get; set; }
  41.         public Engine Engine{ get; set; }
  42.         public Cargo Cargo { get; set; }
  43.        
  44.         public Car(string[] carInfo)
  45.         {
  46.             this.Model = carInfo[0];
  47.             this.Engine = new Engine(int.Parse(carInfo[1]), int.Parse(carInfo[2]));
  48.             this.Cargo = new Cargo(int.Parse(carInfo[3]), carInfo[4]);
  49.         }
  50.  
  51.     }
  52.  
  53.     class Engine
  54.     {
  55.         public int Speed { get; set; }
  56.         public int Power{ get; set; }
  57.  
  58.         public Engine(int speed,int power)
  59.         {
  60.             this.Speed = speed;
  61.             this.Power = power;
  62.         }
  63.     }
  64.  
  65.     class Cargo
  66.     {
  67.         public int Weight { get; set; }
  68.         public string Type { get; set; }
  69.         public Cargo(int weight,string type)
  70.         {
  71.             this.Weight = weight;
  72.             this.Type = type;
  73.         }
  74.     }
  75. }
  76.  
Add Comment
Please, Sign In to add comment