public static void Main() { var carInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var truckInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var busInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var carFuelQuantity = double.Parse(carInfo[1]); var carFuelConsuption = double.Parse(carInfo[2]); var carTankCapacity = double.Parse(carInfo[3]); var truckFuelQuantity = double.Parse(truckInfo[1]); var truckFuelConsuption = double.Parse(truckInfo[2]); var truckTankCapacity = double.Parse(truckInfo[3]); var busFuelQuantity = double.Parse(busInfo[1]); var busFuelConsuption = double.Parse(busInfo[2]); var busTankCapacity = double.Parse(busInfo[3]); Vehicle car = new Car(carFuelQuantity, carFuelConsuption, carTankCapacity); Vehicle truck = new Truck(truckFuelQuantity, truckFuelConsuption, truckTankCapacity); Vehicle bus = new Bus(busFuelQuantity, busFuelConsuption, busTankCapacity); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { try { var inputLine = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var action = inputLine[0]; var vehicle = inputLine[1]; if (action == "Drive") { if (vehicle == "Car") { Console.WriteLine(car.TryTravel(double.Parse(inputLine[2]))); } else if (vehicle == "Truck") { Console.WriteLine(truck.TryTravel(double.Parse(inputLine[2]))); } else { bus.IsLoaded = true; Console.WriteLine(bus.TryTravel(double.Parse(inputLine[2]))); } } else if (action == "Refuel") { if (vehicle == "Car") { car.AddFuel(double.Parse(inputLine[2])); } else if (vehicle == "Bus") { bus.AddFuel(double.Parse(inputLine[2])); } else { truck.AddFuel(double.Parse(inputLine[2])); } } else { bus.IsLoaded = false; Console.WriteLine(bus.TryTravel(double.Parse(inputLine[2]))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:f2}"); }
static void Main(string[] args) { var listVehicles = new List <Vehicle>(); var carInfo = Console.ReadLine().Split(new[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); var car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3])); listVehicles.Add(car); var truckInfo = Console.ReadLine().Split(new[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); var truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3])); listVehicles.Add(truck); var busInfo = Console.ReadLine().Split(new[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); var bus = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3])); listVehicles.Add(bus); var numCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numCommands; i++) { var command = Console.ReadLine() .Split(new[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); var move = command[0].Trim(); var vehicle = command[1].Trim(); var distance = double.Parse(command[2]); if (move == "Drive") { switch (vehicle) { case "Car": car.Drive(distance); break; case "Truck": truck.Drive(distance); break; case "Bus": bus.Drive(distance, fuelIncreasing); break; default: break; } } else if (move == "Refuel") { switch (vehicle) { case "Car": car.AddFuel(distance); break; case "Truck": truck.AddFuel(distance); break; case "Bus": bus.AddFuel(distance); break; default: break; } } else if (move == "DriveEmpty") { bus.Drive(distance); } } foreach (var vehicle in listVehicles) { Console.WriteLine(vehicle.ToString()); } }