public static void Main()
        {
            var allTires   = new List <Tire[]>();
            var allEngines = new List <Engine>();
            var allCars    = new List <Car>();

            while (true)
            {
                var input = Console.ReadLine();
                if (input == "No more tires")
                {
                    break;
                }

                var tires     = input.Split(" ");
                var fourTires = new Tire[4]
                {
                    new Tire(int.Parse(tires[0]), double.Parse(tires[1])),
                    new Tire(int.Parse(tires[2]), double.Parse(tires[3])),
                    new Tire(int.Parse(tires[4]), double.Parse(tires[5])),
                    new Tire(int.Parse(tires[6]), double.Parse(tires[7])),
                };
                allTires.Add(fourTires);
            }

            while (true)
            {
                var input = Console.ReadLine();

                if (input == "Engines done")
                {
                    break;
                }

                var engines = input.Split(" ");
                for (int i = 0; i < engines.Length - 1; i++)
                {
                    var engineHorsePower    = int.Parse(engines[i]);
                    var engineCubicCapacity = double.Parse(engines[i + 1]);
                    var engine = new Engine(engineHorsePower, engineCubicCapacity);
                    allEngines.Add(engine);
                }
            }

            while (true)
            {
                var input = Console.ReadLine();
                if (input == "Show special")
                {
                    break;
                }

                var carInfo         = input.Split();
                var make            = carInfo[0];
                var model           = carInfo[1];
                var year            = int.Parse(carInfo[2]);
                var fuelQuantity    = double.Parse(carInfo[3]);
                var fuelConsumption = double.Parse(carInfo[4]);
                var engineIndex     = int.Parse(carInfo[5]);
                var tireIndex       = int.Parse(carInfo[6]);
                var car             = new Car(make, model, year, fuelQuantity, fuelConsumption, allEngines[engineIndex], allTires[tireIndex]);
                var isSpecialCar    = IsSpecialCar(car);
                if (isSpecialCar)
                {
                    car.Drive(distance);
                }

                if (car.FuelQuantity != fuelQuantity)
                {
                    allCars.Add(car);
                }
            }

            foreach (var specialCar in allCars)
            {
                Console.WriteLine($"Make: {specialCar.Make}");
                Console.WriteLine($"Model: {specialCar.Model}");
                Console.WriteLine($"Year: {specialCar.Year}");
                Console.WriteLine($"HorsePowers: {specialCar.Engine.HorsePower}");
                Console.WriteLine($"FuelQuantity: {specialCar.FuelQuantity}");
            }
        }
Example #2
0
        public static void Main()
        {
            string        input          = Console.ReadLine();
            List <Tire[]> tireCollection = new List <Tire[]>();

            while (input != "No more tires")
            {
                Tire[]   currentTireCollection = new Tire[4];
                string[] tiresAsString         = input.Split();
                for (int i = 0; i < currentTireCollection.Length; i++)
                {
                    int    year        = int.Parse(tiresAsString[i * 2]);
                    double pressure    = double.Parse(tiresAsString[i * 2 + 1]);
                    Tire   currentTire = new Tire()
                    {
                        Pressure = pressure,
                        Year     = year
                    };

                    currentTireCollection[i] = currentTire;
                }

                tireCollection.Add(currentTireCollection);
                input = Console.ReadLine();
            }

            input = Console.ReadLine();
            List <Engine> engineCollection = new List <Engine>();

            while (input != "Engines done")
            {
                string[] enginesParams = input.Split();
                int      horsePower    = int.Parse(enginesParams[0]);
                double   cubicCapacity = double.Parse(enginesParams[1]);
                Engine   currentEngine = new Engine()
                {
                    CubicCapacity = cubicCapacity,
                    HorsePower    = horsePower
                };

                engineCollection.Add(currentEngine);
                input = Console.ReadLine();
            }

            input = Console.ReadLine();
            List <Car> carCollection = new List <Car>();

            while (input != "Show special")
            {
                string[] carParams           = input.Split();
                string   make                = carParams[0];
                string   model               = carParams[1];
                int      year                = int.Parse(carParams[2]);
                double   fuelQuantity        = double.Parse(carParams[3]);
                double   fuelConsumption     = double.Parse(carParams[4]);
                int      engineIndex         = int.Parse(carParams[5]);
                int      tireCollectionIndex = int.Parse(carParams[6]);
                Car      currentCar          = new Car()
                {
                    Make            = make,
                    Model           = model,
                    Year            = year,
                    FuelQuantity    = fuelQuantity,
                    FuelConsumption = fuelConsumption,
                    Engine          = engineCollection[engineIndex],
                    Tires           = tireCollection[tireCollectionIndex]
                };

                carCollection.Add(currentCar);
                input = Console.ReadLine();
            }

            foreach (var car in carCollection
                     .Where(c => c.Year >= 2017)
                     .Where(c => c.Engine.HorsePower > 330)
                     .Where(c => c.Tires
                            .Select(p => p.Pressure)
                            .Sum() >= 9 &&
                            c.Tires
                            .Select(p => p.Pressure)
                            .Sum() <= 10))
            {
                car.Drive(20);
                Console.WriteLine(car.GetInformation());
            }
        }