Beispiel #1
0
        public Car(string make, string model, int year, double fuelQuantity, double fuelConsumption, Engine engine, Tire[] tires)
            : this(make, model, year, fuelQuantity, fuelConsumption)

        {
            this.Engine = engine;
            this.Tires  = tires;
        }
Beispiel #2
0
 public Car(string Make, string Model, int Year, double FuelQuantity, double FuelConsumption, Engine Engine,
            Tyre[] tyre)
     : this(Make, Model, Year, FuelQuantity, FuelConsumption)
 {
     this.engine = Engine;
     Tyres       = tyres;
 }
        static void Main()
        {
            List <Tire[]> tires = new List <Tire[]>();

            string inputTiresInfo = Console.ReadLine();

            while (inputTiresInfo != "No more tires")
            {
                double[] tiresInfo = inputTiresInfo
                                     .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                     .Select(double.Parse)
                                     .ToArray();

                var currentTires = new Tire[4]
                {
                    new Tire((int)tiresInfo[0], tiresInfo[1]),
                    new Tire((int)tiresInfo[2], tiresInfo[3]),
                    new Tire((int)tiresInfo[4], tiresInfo[5]),
                    new Tire((int)tiresInfo[6], tiresInfo[7]),
                };

                tires.Add(currentTires);

                inputTiresInfo = Console.ReadLine();
            }

            List <Engine> engines = new List <Engine>();

            string inputEngineInfo = Console.ReadLine();

            while (inputEngineInfo != "Engines done")
            {
                string[] engineInfo = inputEngineInfo
                                      .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                      .ToArray();

                int    horsePower    = int.Parse(engineInfo[0]);
                double cubicCapacity = double.Parse(engineInfo[1]);

                Engine engine = new Engine(horsePower, cubicCapacity);

                engines.Add(engine);

                inputEngineInfo = Console.ReadLine();
            }

            string inputCarInfo = Console.ReadLine();

            List <Car> cars = new List <Car>();

            while (inputCarInfo != "Show special")
            {
                string[] carInfo = inputCarInfo
                                   .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                   .ToArray();

                string make            = carInfo[0];
                string model           = carInfo[1];
                int    year            = int.Parse(carInfo[2]);
                double fuelQuantity    = double.Parse(carInfo[3]);
                double fuelConsumption = double.Parse(carInfo[4]);
                int    engineIndex     = int.Parse(carInfo[5]);
                int    tiresIndex      = int.Parse(carInfo[6]);

                Car car = new Car(make, model, year, fuelQuantity, fuelConsumption, engines[engineIndex], tires[tiresIndex]);

                cars.Add(car);

                inputCarInfo = Console.ReadLine();
            }

            foreach (var currentCar in cars)
            {
                bool   checkYear       = currentCar.Year >= 2017;
                bool   checkHorsePower = currentCar.Engine.HorsePower > 330;
                double totalPressure   = 0;

                foreach (var currentPressure in currentCar.Tires)
                {
                    totalPressure += currentPressure.Pressure;
                }
                bool checkPressure = totalPressure >= 9 && totalPressure <= 10;

                if (checkYear && checkHorsePower && checkPressure)
                {
                    currentCar.Drive(20);

                    Console.WriteLine(currentCar.CarInfo());
                }
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            List <Tire[]> tires   = new List <Tire[]>();
            List <Engine> engines = new List <Engine>();
            List <Car>    cars    = new List <Car>();
            string        command = Console.ReadLine();

            while (command != "No more tires")
            {
                Tire[]   tireCollection = new Tire[4];
                string[] tireInfo       = command.Split(" ");
                int      counter        = 0;

                for (int i = 0; i < tireInfo.Length; i += 2)
                {
                    int    year     = int.Parse(tireInfo[i]);
                    double pressure = double.Parse(tireInfo[i + 1]);

                    Tire tire = new Tire(year, pressure);
                    tireCollection[counter] = tire;

                    counter++;
                }

                tires.Add(tireCollection);
                command = Console.ReadLine();
            }

            command = Console.ReadLine();
            while (command != "Engines done")
            {
                string[] engineInfo = command.Split(" ");

                int    horsePower    = int.Parse(engineInfo[0]);
                double cubicCapacity = double.Parse(engineInfo[1]);

                Engine engine = new Engine(horsePower, cubicCapacity);
                engines.Add(engine);

                command = Console.ReadLine();
            }

            command = Console.ReadLine();
            while (command != "Show special")
            {
                string[] carInfo         = command.Split(" ");
                string   make            = carInfo[0];
                string   model           = carInfo[1];
                int      year            = int.Parse(carInfo[2]);
                int      fuelQuantity    = int.Parse(carInfo[3]);
                int      fuelConsumption = int.Parse(carInfo[4]);
                Engine   engine          = engines.ElementAt(int.Parse(carInfo[5]));
                Tire[]   currentTires    = tires.ElementAt(int.Parse(carInfo[6]));

                Car car = new Car(make, model, year, fuelQuantity, fuelConsumption, engine, currentTires);
                cars.Add(car);

                command = Console.ReadLine();
            }

            List <Car> specials = cars
                                  .Where(x => x.Year >= 2017 &&
                                         x.Engine.HorsePower > 330 &&
                                         (x.Tires.Sum(x => x.Pressure) > 9 && x.Tires.Sum(x => x.Pressure) < 10))
                                  .ToList();

            specials.ForEach(x => x.Drive(20));

            specials.ForEach(x =>
            {
                Console.WriteLine($"Make: {x.Make}");
                Console.WriteLine($"Model: {x.Model}");
                Console.WriteLine($"Year: {x.Year}");
                Console.WriteLine($"HorsePowers: {x.Engine.HorsePower}");
                Console.WriteLine($"FuelQuantity: {x.FuelQuantity}");
            });
        }
Beispiel #5
0
        public static void Main()
        {
            var tireInformation = Console.ReadLine();
            var tiresList       = new List <Tire[]>();

            while (tireInformation != "No more tires")
            {
                var tokens  = tireInformation.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var tires   = new Tire[4];
                var counter = 0;

                for (int i = 0; i < tokens.Length - 1; i += 2)
                {
                    var year     = int.Parse(tokens[i]);
                    var pressure = double.Parse(tokens[i + 1]);

                    tires[counter++] = new Tire(year, pressure);
                }

                tiresList.Add(tires);
                tireInformation = Console.ReadLine();
            }

            var engineInformation = Console.ReadLine();
            var enginesList       = new List <Engine>();

            while (engineInformation != "Engines done")
            {
                var tokens        = engineInformation.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var horsePower    = int.Parse(tokens[0]);
                var cubicCapacity = double.Parse(tokens[1]);

                var engine = new Engine(horsePower, cubicCapacity);
                enginesList.Add(engine);
                engineInformation = Console.ReadLine();
            }

            var carInformation = Console.ReadLine();
            var carsList       = new List <Car>();

            while (carInformation != "Show special")
            {
                var tokens          = carInformation.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                var make            = tokens[0];
                var model           = tokens[1];
                var year            = int.Parse(tokens[2]);
                var fuelQuantity    = double.Parse(tokens[3]);
                var fuelConsumption = double.Parse(tokens[4]);
                var engineIndex     = int.Parse(tokens[5]);
                var tiresIndex      = int.Parse(tokens[6]);

                carsList.Add(new Car(make, model, year, fuelQuantity, fuelConsumption, enginesList[engineIndex], tiresList[tiresIndex]));
                carInformation = Console.ReadLine();
            }

            Func <Tire[], bool> pressureSumFunc;

            pressureSumFunc = x => x.Select(y => y.Pressure).Sum() > 9 && x.Select(y => y.Pressure).Sum() < 10;

            foreach (var car in carsList
                     .Where(x => x.Year >= 2017)
                     .Where(x => x.Engine.HorsePower > 330)
                     .Where(x => pressureSumFunc(x.Tires)))
            {
                car.Drive(20);
                Console.WriteLine($"Make: {car.Make}");
                Console.WriteLine($"Model: {car.Model}");
                Console.WriteLine($"Year: {car.Year}");
                Console.WriteLine($"HorsePowers: {car.Engine.HorsePower}");
                Console.WriteLine($"FuelQuantity: {car.FuelQuantity}");
            }
        }