public Car() { this.Model = model; this.Engine = new Engine(); this.Cargo = new Cargo(); this.Tires = new Tires(); }
public Car(string[] car) : this() { var model = car[0]; int speed = int.Parse(car[1]); int power = int.Parse(car[2]); int weight = int.Parse(car[3]); string type = car[4]; double tire1Pressure = double.Parse(car[5]); int tire1Age = int.Parse(car[6]); double tire2Pressure = double.Parse(car[7]); int tire2Age = int.Parse(car[8]); double tire3Pressure = double.Parse(car[9]); int tire3Age = int.Parse(car[10]); double tire4Pressure = double.Parse(car[11]); int tire4Age = int.Parse(car[12]); this.Model = model; this.Engine = new Engine(speed, power); this.Cargo = new Cargo(weight, type); this.Tires = new Tires(tire1Pressure, tire1Age, tire2Pressure, tire2Age, tire3Pressure, tire3Age, tire4Pressure, tire4Age); }
static void Main(string[] args) { List <Car> carList = new List <Car>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(" "); string model = input[0]; Engine engine = new Engine(int.Parse(input[1]), int.Parse(input[2])); Cargo cargo = new Cargo(int.Parse(input[3]), input[4]); Tires[] tire = new Tires[] { new Tires(int.Parse(input[6]), double.Parse(input[5])), new Tires(int.Parse(input[8]), double.Parse(input[7])), new Tires(int.Parse(input[10]), double.Parse(input[9])), new Tires(int.Parse(input[12]), double.Parse(input[11])) }; Car car = new Car(model, cargo, engine, tire); carList.Add(car); } string command = Console.ReadLine(); if (command == "fragile") { carList.Where(x => x.Tire.Any(t => t.Pressure < 1)) .Where(x => x.Cargo.CargoType == "fragile") .ToList().ForEach(x => Console.WriteLine(x.Model)); } else if (command == "flamable") { carList.Where(x => x.Engine.EnginePower > 250) .Where(x => x.Cargo.CargoType == "flamable") .ToList() .ForEach(x => Console.WriteLine(x.Model)); } }
static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < n; i++) { string[] info = Console.ReadLine().Split(); string model = info[0]; int engineSpeed = int.Parse(info[1]); int enginePower = int.Parse(info[2]); Engine engine = new Engine(engineSpeed, enginePower); int cargoWeight = int.Parse(info[3]); string cargoType = info[4]; Cargo cargo = new Cargo(cargoWeight, cargoType); double tire1Pressure = double.Parse(info[5]); int tire1Year = int.Parse(info[6]); Tires tire1 = new Tires(tire1Pressure, tire1Year); double tire2Pressure = double.Parse(info[7]); int tire2Year = int.Parse(info[8]); Tires tire2 = new Tires(tire2Pressure, tire2Year); double tire3Pressure = double.Parse(info[9]); int tire3Year = int.Parse(info[10]); Tires tire3 = new Tires(tire3Pressure, tire3Year); double tire4Pressure = double.Parse(info[11]); int tire4Year = int.Parse(info[12]); Tires tire4 = new Tires(tire4Pressure, tire4Year); List <Tires> tires = new List <Tires> { tire1, tire2, tire3, tire4 }; Car car = new Car(model, engine, cargo, tires); cars.Add(car); } string command = Console.ReadLine(); if (command == "fragile") { List <Car> fragileCars = new List <Car>(); fragileCars = cars.Where(c => c.Cargo.CargoType == "fragile") .Where(c => c.Tires.Any(p => p.TirePressure < 1)).ToList(); foreach (Car car in fragileCars) { Console.WriteLine(car.Model); } //cars.Where(c => c.Cargo.CargoType == "fragile").Where(c => c.Tires.Any(t => t.TirePressure < 1)) //.Select(c => c.Model).ToList().ForEach(m => Console.WriteLine(m)); } else if (command == "flamable") { List <Car> flamableCars = new List <Car>(); flamableCars = cars.Where(c => c.Cargo.CargoType == "flamable") .Where(c => c.Engine.EnginePower > 250).ToList(); foreach (Car car in flamableCars) { Console.WriteLine(car.Model); } //cars.Where(c => c.Cargo.CargoType == "flamable").Where(c => c.Engine.EnginePower > 250) //.Select(c => c.Model).ToList().ForEach(m => Console.WriteLine(m)); } }