private static void AddTires(string input, List <Tire[]> allTires) { int addedTiresCount = 0; var tires = new Tire[4]; var tireInfo = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < tireInfo.Length; i += 2) { if (i % 2 == 0) { int year = int.Parse(tireInfo[i]); double pressure = double.Parse(tireInfo[i + 1]); Tire tire = new Tire(year, pressure); tires[addedTiresCount] = tire; addedTiresCount++; } } allTires.Add(tires); }
static void Main(string[] args) { var tires = new List <Tire[]>(); while (true) { string command = Console.ReadLine(); if (command == "No more tires") { break; } var tireInfo = command.Split(" ", StringSplitOptions.RemoveEmptyEntries); var year = int.Parse(tireInfo[0]); var pressure = double.Parse(tireInfo[1]); var tire1 = new Tire(year, pressure); year = int.Parse(tireInfo[2]); pressure = double.Parse(tireInfo[3]); var tire2 = new Tire(year, pressure); year = int.Parse(tireInfo[4]); pressure = double.Parse(tireInfo[5]); var tire3 = new Tire(year, pressure); year = int.Parse(tireInfo[6]); pressure = double.Parse(tireInfo[7]); var tire4 = new Tire(year, pressure); tires.Add(new Tire[4] { tire1, tire2, tire3, tire4, }); } var engines = new List <Engine>(); while (true) { string command = Console.ReadLine(); if (command == "Engines done") { break; } var engineInfo = command.Split(" ", StringSplitOptions.RemoveEmptyEntries); var horsePower = int.Parse(engineInfo[0]); var cubicCapacity = double.Parse(engineInfo[1]); engines.Add(new Engine(horsePower, cubicCapacity)); } var cars = new List <Car>(); while (true) { string command = Console.ReadLine(); if (command == "Show special") { break; } var carInfo = command.Split(" ", StringSplitOptions.RemoveEmptyEntries); 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 tiresIndex = int.Parse(carInfo[6]); var car = new Car(make, model, year, fuelQuantity, fuelConsumption, engines[engineIndex], tires[tiresIndex]); cars.Add(car); } foreach (var car in cars .Where(x => x.Year >= 2017) .Where(x => x.Engine.HorsePower > 330) .Where(x => x.Tires.Sum(y => y.Pressure) >= 9 && x.Tires.Sum(y => y.Pressure) <= 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}"); } }
static void Main(string[] args) { List <Tire[]> tires = new List <Tire[]>(); string tireInput = string.Empty; while ((tireInput = Console.ReadLine()) != "No more tires") { string[] tireTokens = tireInput.Split(); Tire[] tireSet = new Tire[] { new Tire(int.Parse(tireTokens[0]), double.Parse(tireTokens[1])), new Tire(int.Parse(tireTokens[2]), double.Parse(tireTokens[3])), new Tire(int.Parse(tireTokens[4]), double.Parse(tireTokens[5])), new Tire(int.Parse(tireTokens[6]), double.Parse(tireTokens[7])) }; tires.Add(tireSet); } List <Engine> engines = new List <Engine>(); string engineInput = string.Empty; while ((engineInput = Console.ReadLine()) != "Engines done") { string[] engineTokens = engineInput.Split(); Engine engine = new Engine(int.Parse(engineTokens[0]), double.Parse(engineTokens[1])); engines.Add(engine); } List <Car> cars = new List <Car>(); string carProps = string.Empty; while ((carProps = Console.ReadLine()) != "Show special") { string[] props = carProps.Split(); string make = props[0]; string model = props[1]; int year = int.Parse(props[2]); double fuelQuantity = double.Parse(props[3]); double fuelConsumption = double.Parse(props[4]); int engineIndex = int.Parse(props[5]); int tiresIndex = int.Parse(props[6]); Car car = new Car(make, model, year, fuelQuantity, fuelConsumption, engines[engineIndex], tires[tiresIndex]); cars.Add(car); } foreach (var car in cars .Where(car => car.Year >= 2017) .Where(hp => hp.Engine.HorsePower >= 330) .Where(x => x.Tires.Sum(y => y.Pressure) >= 9 && x.Tires.Sum(y => y.Pressure) <= 10)) { car.FuelQuantity -= car.FuelConsumption * 20 / 100; StringBuilder sb = new StringBuilder(); sb.AppendLine($"Make: {car.Make}"); sb.AppendLine($"Model: {car.Model}"); sb.AppendLine($"Year: {car.Year}"); sb.AppendLine($"HorsePowers: {car.Engine.HorsePower}"); sb.Append($"FuelQuantity: {car.FuelQuantity}"); Console.WriteLine(sb.ToString()); } }
public static void Main() { List <Tire[]> tires = new List <Tire[]>(); List <Engine> engines = new List <Engine>(); List <Car> cars = new List <Car>(); string input = Console.ReadLine(); while (input != "No more tires") { var tiresInfo = input .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); var currentTires = new Tire[4] { new Tire(int.Parse(tiresInfo[0]), double.Parse(tiresInfo[1])), new Tire(int.Parse(tiresInfo[2]), double.Parse(tiresInfo[3])), new Tire(int.Parse(tiresInfo[4]), double.Parse(tiresInfo[5])), new Tire(int.Parse(tiresInfo[6]), double.Parse(tiresInfo[7])), }; tires.Add(currentTires); input = Console.ReadLine(); } input = Console.ReadLine(); while (input != "Engines done") { var enginesInfo = input .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); int horsePower = int.Parse(enginesInfo[0]); double cubicCapacity = double.Parse(enginesInfo[1]); var engine = new Engine(horsePower, cubicCapacity); engines.Add(engine); input = Console.ReadLine(); } input = Console.ReadLine(); while (input != "Show special") { var carsInfo = input .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); string make = carsInfo[0]; string model = carsInfo[1]; int year = int.Parse(carsInfo[2]); double fuelQuantity = double.Parse(carsInfo[3]); double fuelConsumption = double.Parse(carsInfo[4]); int engineIndex = int.Parse(carsInfo[5]); int tiresIndex = int.Parse(carsInfo[6]); var car = new Car(make, model, year, fuelQuantity, fuelConsumption, engines[engineIndex], tires[tiresIndex]); cars.Add(car); input = Console.ReadLine(); } string result = GetSpecialCars(cars); Console.WriteLine(result); }
public static void Main(string[] args) { List <Tire[]> tireSets = new List <Tire[]>(); while (true) { string command = Console.ReadLine(); if (command == "No more tires") { break; } string[] tokens = command.Split(); int yearOne = int.Parse(tokens[0]); int yearTwo = int.Parse(tokens[2]); int yearThree = int.Parse(tokens[4]); int yearFour = int.Parse(tokens[6]); double pressureOne = double.Parse(tokens[1]); double pressureTwo = double.Parse(tokens[3]); double pressureThree = double.Parse(tokens[5]); double pressure4 = double.Parse(tokens[7]); var tires = new Tire[4] { new Tire(yearOne, pressureOne), new Tire(yearTwo, pressureTwo), new Tire(yearThree, pressureThree), new Tire(yearFour, pressure4), }; tireSets.Add(tires); } List <Engine> engines = new List <Engine>(); while (true) { string command = Console.ReadLine(); if (command == "Engines done") { break; } string[] tokens = command.Split(); int horsePower = int.Parse(tokens[0]); double cubicCapacity = double.Parse(tokens[1]); Engine engine = new Engine(horsePower, cubicCapacity); engines.Add(engine); } List <Car> cars = new List <Car>(); while (true) { string command = Console.ReadLine(); if (command == "Show special") { break; } string[] tokens = command.Split(); string make = tokens[0]; string model = tokens[1]; int year = int.Parse(tokens[2]); double fuelQuantity = double.Parse(tokens[3]); double fuelConsumption = double.Parse(tokens[4]); int engineIndex = int.Parse(tokens[5]); int tiresIndex = int.Parse(tokens[6]); int horsePower = engines[engineIndex].HorsePower; double pressureSum = 0; var neededSet = tireSets[tiresIndex]; foreach (var tire in neededSet) { pressureSum += tire.Pressure; } Car car = new Car(make, model, year, fuelQuantity, fuelConsumption, engines[engineIndex], tireSets[tiresIndex]); car.Engine.HorsePower = horsePower; if (pressureSum >= 9 && pressureSum <= 10 && car.Year >= 2017 && horsePower > 330) { cars.Add(car); } } 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}"); } }