Advertisement
elena1234

SpecialCars-StartUp (class)

Feb 4th, 2021
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.31 KB | None | 0 0
  1. using System;
  2. using CarEngineAndTires;
  3. using System.Collections.Generic;
  4. using CarConstructors;
  5. using System.Linq;
  6.  
  7. namespace SpecialCars
  8. {
  9.     public static class StartUp
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var listOfTires = new List<Tire[]>();
  14.             var listOftEngines = new List<Engine>();
  15.             var listOfCars = new List<Car>();
  16.  
  17.             string commandForTires;
  18.             while ((commandForTires = Console.ReadLine()) != "No more tires")
  19.             {
  20.                 string[] tireInfo = commandForTires.Split(" ", StringSplitOptions.RemoveEmptyEntries);
  21.                 var tempListOfTires = new List<Tire>();
  22.                 for (int i = 0; i < 8; i+=2)
  23.                 {
  24.                     int year = int.Parse(tireInfo[i]);
  25.                     double pressure = double.Parse(tireInfo[i+1]);
  26.                     var currentTire = new Tire(year, pressure);
  27.                     tempListOfTires.Add(currentTire);
  28.                 }
  29.  
  30.                 var currentArrayOfTires = tempListOfTires.ToArray();
  31.                 listOfTires.Add(currentArrayOfTires);              
  32.             }
  33.  
  34.             string commandForEngine;
  35.             while ((commandForEngine = Console.ReadLine()) != "Engines done")
  36.             {
  37.                 string[] engineInfo = commandForEngine.Split(" ", StringSplitOptions.RemoveEmptyEntries);
  38.                 int hoursePower = int.Parse(engineInfo[0]);
  39.                 double cubicCapacity = double.Parse(engineInfo[1]);
  40.                 var newEngine = new Engine(hoursePower, cubicCapacity);
  41.                 listOftEngines.Add(newEngine);
  42.             }
  43.  
  44.             string commandForCar;
  45.             while ((commandForCar = Console.ReadLine()) != "Show special")
  46.             {
  47.                 string[] carInfo = commandForCar.Split(" ", StringSplitOptions.RemoveEmptyEntries);
  48.                 string make = carInfo[0];
  49.                 string model = carInfo[1];
  50.                 int year = int.Parse(carInfo[2]);
  51.                 double fuelQuantity = double.Parse(carInfo[3]);
  52.                 double fuelConsumption = double.Parse(carInfo[4]);
  53.                 int engineIndex = int.Parse(carInfo[5]);
  54.                 int tiresIndex = int.Parse(carInfo[6]);
  55.                 if (engineIndex >= 0 && engineIndex < listOftEngines.Count && tiresIndex >= 0 && tiresIndex < listOfTires.Count)
  56.                 {
  57.                     Engine engine = listOftEngines[engineIndex];
  58.                     Tire[] tires = listOfTires[tiresIndex];                
  59.                    
  60.                     var newCar = new Car(make, model, year, fuelQuantity, fuelConsumption, engine, tires);
  61.                     listOfCars.Add(newCar);
  62.                 }
  63.             }
  64.  
  65.             var filterCars = listOfCars.Where(car => car.Year >= 2017 && car.Engine.HorsePower > 330).ToList();
  66.             foreach (var car in filterCars)
  67.             {
  68.                 double sumOfPressure = 0;
  69.                 foreach (var tire in car.Tires)
  70.                 {
  71.                     sumOfPressure += tire.Pressure;
  72.                 }
  73.  
  74.                 if (sumOfPressure >= 9 && sumOfPressure <= 10)
  75.                 {
  76.                     car.Drive(20);
  77.                     Console.WriteLine(car.WhoAmI());
  78.                 }
  79.             }
  80.         }      
  81.     }
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement