static void Main(string[] args) { var input = Console.ReadLine(); var tires = new List<Tire[]>(); var engines = new List<Engine>(); var cars = new List<Car>(); while (input != "No more tires") { var tireInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries); var tire1 = new Tire(int.Parse(tireInfo[0]), double.Parse(tireInfo[1])); var tire2 = new Tire(int.Parse(tireInfo[2]), double.Parse(tireInfo[3])); var tire3 = new Tire(int.Parse(tireInfo[4]), double.Parse(tireInfo[5])); var tire4 = new Tire(int.Parse(tireInfo[6]), double.Parse(tireInfo[7])); tires.Add(new Tire[] { tire1, tire2, tire3, tire4 }); input = Console.ReadLine(); } input = Console.ReadLine(); while (input != "Engines done") { var engineInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries); var horsePower = int.Parse(engineInfo[0]); var cubicCapacity = double.Parse(engineInfo[1]); var engin = new Engine(horsePower, cubicCapacity); engines.Add(engin); input = Console.ReadLine(); } input = Console.ReadLine(); while (input != "Show special") { //Audi A5 2017 200 12 0 0 var carInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries); var make = carInfo[0]; var model = carInfo[1]; var year = int.Parse(carInfo[2]); var fuelQuantity = double.Parse(carInfo[3]); var fuelCapacity = double.Parse(carInfo[4]); var engine = engines[int.Parse(carInfo[5])]; var tire = tires[int.Parse(carInfo[6])]; var car = new Car(make, model, year, fuelQuantity, fuelCapacity, engine, tire); cars.Add(car); input = Console.ReadLine(); } cars = cars .Where(y => y.Year >= 2017) .Where(h=>h.Engine.HorsePower >= 330) .Where(p => p.Tires.Sum(x=>x.Pressure)>= 9) .Where(p=>p.Tires.Sum(x=>x.Pressure) <= 10) .ToList(); foreach (var car in cars) { 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}"); } }
static void Main() { var tireList = new List <Tire[]>(); var engineList = new List <Engine>(); var carList = new List <Car>(); string tireInfo = Console.ReadLine(); while (tireInfo != "No more tires!") { var currentTyre = tireInfo.Split(); var currentSet = new Tire[4] { new Tire(int.Parse(currentTyre[0]), double.Parse(currentTyre[1])), new Tire(int.Parse(currentTyre[2]), double.Parse(currentTyre[3])), new Tire(int.Parse(currentTyre[4]), double.Parse(currentTyre[5])), new Tire(int.Parse(currentTyre[6]), double.Parse(currentTyre[7])), }; tireList.Add(currentSet); tireInfo = Console.ReadLine(); } var engineInfo = Console.ReadLine(); while (engineInfo != "Engines done") { var curEngine = engineInfo.Split(); Engine engine = new Engine(int.Parse(curEngine[0]), double.Parse(curEngine[1])); engineList.Add(engine); engineInfo = Console.ReadLine(); } var carInfo = Console.ReadLine(); while (carInfo != "Show special") { var currentCar = carInfo.Split(); string make = currentCar[0]; string model = currentCar[1]; int year = int.Parse(currentCar[2]); double fuelQuantity = double.Parse(currentCar[3]); double fuelConsumption = double.Parse(currentCar[4]); int engineIndex = int.Parse(currentCar[5]); int tiresIndex = int.Parse(currentCar[6]); Car car = new Car( make, model, year, fuelQuantity, fuelConsumption, engineList.ElementAt(engineIndex), tireList.ElementAt(tiresIndex)); carList.Add(car); carInfo = Console.ReadLine(); } var filteredCarList = carList .Where(x => x.Year == 2017) .Where(x => x.Engine.HorsePower >= 330) .Where(x => x.Tires.Select(y => y.Pressure).Sum() >= 9) .Where(x => x.Tires.Select(y => y.Pressure).Sum() <= 10) .ToList(); foreach (var car in filteredCarList) { 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}"); } }
static void Main(string[] args) { List <string> tiresArray = new List <string>(); List <string> engineArray = new List <string>(); List <string> carArray = new List <string>(); string tiresInput = Console.ReadLine(); while (tiresInput != "No more tires") { tiresArray.Add(tiresInput); tiresInput = Console.ReadLine(); } string engineInput = Console.ReadLine(); while (engineInput != "Engines done") { engineArray.Add(engineInput); engineInput = Console.ReadLine(); } string carInput = Console.ReadLine(); while (carInput != "Show special") { carArray.Add(carInput); carInput = Console.ReadLine(); } var carOutput = new List <string>(); for (int i = 0; i < carArray.Count; i++) { string[] c = carArray[i].Split(); string make = c[0]; string model = c[1]; int year = int.Parse(c[2]); double fuelQuantity = double.Parse(c[3]); double fuelConsumption = double.Parse(c[4]); int engineIndex = int.Parse(c[5]); int tireIndex = int.Parse(c[6]); string[] e = engineArray[engineIndex].Split(); var engine = new Engine(int.Parse(e[0]), double.Parse(e[1])); double sum = 0; string[] t = tiresArray[tireIndex].Split(); sum = double.Parse(t[1]) + double.Parse(t[3]) + double.Parse(t[5]) + double.Parse(t[7]); var tires = new Tire[4] { new Tire(int.Parse(t[0]), double.Parse(t[1])), new Tire(int.Parse(t[2]), double.Parse(t[3])), new Tire(int.Parse(t[4]), double.Parse(t[5])), new Tire(int.Parse(t[6]), double.Parse(t[7])), }; Car car = new Car(make, model, year, fuelQuantity, fuelConsumption, engine, tires); if (year >= 2017 && engine.HorsePower > 330 && sum > 9 && sum < 10) { 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}"); } } }