Пример #1
0
        private static void Main(string[] args)
        {
            List <Car> cars = new List <Car>();

            int lines = int.Parse(Console.ReadLine());

            for (int i = 0; i < lines; i++)
            {
                string[] parameters = Console.ReadLine()
                                      .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string model       = parameters[0];
                int    engineSpeed = int.Parse(parameters[1]);
                int    enginePower = int.Parse(parameters[2]);
                int    cargoWeight = int.Parse(parameters[3]);
                string cargoType   = parameters[4];

                var engine = new Engine(enginePower, engineSpeed);
                var cargo  = new Cargo(cargoType, cargoWeight);
                var tires  = new List <Tires>();

                for (int j = 5; j < parameters.Length; j += 2)
                {
                    var pressure = double.Parse(parameters[j]);
                    var age      = int.Parse(parameters[j + 1]);

                    var tire = new Tires(age, pressure);

                    tires.Add(tire);
                }

                var car = new Car(model, engine, cargo, tires);

                cars.Add(car);
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                List <string> fragile = cars
                                        .Where(x => x.Cargo.CargoType == "fragile" && x.Tires.Any(y => y.Pressure < 1))
                                        .Select(x => x.Model)
                                        .ToList();

                Console.WriteLine(string.Join(Environment.NewLine, fragile));
            }
            else
            {
                List <string> flamable = cars
                                         .Where(x => x.Cargo.CargoType == "flamable" && x.Engine.Power > 250)
                                         .Select(x => x.Model)
                                         .ToList();

                Console.WriteLine(string.Join(Environment.NewLine, flamable));
            }
        }
Пример #2
0
        private static Tires[] GetTiresParameters(string[] parameters)
        {
            Tires[] tires;
            double  tire1Pressure = double.Parse(parameters[5]);
            int     tire1age      = int.Parse(parameters[6]);
            double  tire2Pressure = double.Parse(parameters[7]);
            int     tire2age      = int.Parse(parameters[8]);
            double  tire3Pressure = double.Parse(parameters[9]);
            int     tire3age      = int.Parse(parameters[10]);
            double  tire4Pressure = double.Parse(parameters[11]);
            int     tire4age      = int.Parse(parameters[12]);

            tires    = new Tires[4];
            tires[0] = new Tires(tire1Pressure, tire1age);
            tires[1] = new Tires(tire2Pressure, tire2age);
            tires[2] = new Tires(tire3Pressure, tire3age);
            tires[3] = new Tires(tire4Pressure, tire4age);
            return(tires);
        }
Пример #3
0
        public Car(string input)
        {
            string[] parameters = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            this.Model = parameters[0];
            int engineSpeed = int.Parse(parameters[1]);
            int enginePower = int.Parse(parameters[2]);

            this.Engine = new Engine(engineSpeed, enginePower);
            int    cargoWeight = int.Parse(parameters[3]);
            string cargoType   = parameters[4];

            this.Cargo = new Cargo(cargoWeight, cargoType);
            Queue <string> tires = new Queue <string>(parameters.Skip(5));

            while (tires.Count >= 2)
            {
                double tirePressure = double.Parse(tires.Dequeue());
                int    tireAge      = int.Parse(tires.Dequeue());
                Tires.Add(new Tire(tirePressure, tireAge));
            }
        }
Пример #4
0
 public static void AddNewCarInGarage(string model, Engine engine, Cargo cargo, Tires tires)
 {
     Garage.AddCarInGarage(new Car(model, engine, cargo, tires));
 }