public static Car Parse(string[] input) { //<Model> <EngineSpeed> <EnginePower> <CargoWeight> <CargoType> <Tire1Pressure> <Tire1Age> <Tire2Pressure> <Tire2Age> <Tire3Pressure> <Tire3Age> <Tire4Pressure> <Tire4Age> var model = input[0]; var engine = Engine.Parse(input.Skip(1).Take(2).ToArray()); var cargo = Cargo.Parse(input.Skip(3).Take(2).ToArray()); var tiresData = input.Skip(5).ToArray(); var tires = new Tire[4]; for (var i = 0; i < 4; i++) { var currentTireData = tiresData.Skip(2 * i).Take(2).ToArray(); var curretnTire = Tire.Parse(currentTireData); tires[i] = curretnTire; } return(new Car(model, engine, cargo, tires)); }
private static List <Car> ReadCars() { int amountOfCars = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int line = 0; line < amountOfCars; line++) { string[] inputArgs = Console.ReadLine().Split(); string model = inputArgs[0]; int engineSpeed = int.Parse(inputArgs[1]); int enginePower = int.Parse(inputArgs[2]); Engine engine = new Engine(engineSpeed, enginePower); int cargoWeight = int.Parse(inputArgs[3]); string cargoType = inputArgs[4]; Cargo cargo = new Cargo(cargoWeight, cargoType); List <Tire> tiresOfACar = new List <Tire>(); int counter = 4; for (int i = 1; i <= 4; i++) { double tirePressure = double.Parse(inputArgs[i + counter]); int tireAge = int.Parse(inputArgs[i + counter + 1]); Tire tire = new Tire(tirePressure, tireAge); tiresOfACar.Add(tire); counter++; } Car car = new Car(model, engine, cargo, tiresOfACar); cars.Add(car); } return(cars); }