public void Run() { string[] carInfo = Console.ReadLine().Split(); string[] truckInfo = Console.ReadLine().Split(); string[] busInfo = Console.ReadLine().Split(); double carFuelConsumption = double.Parse(carInfo[2]); double carFuelQuantity = double.Parse(carInfo[1]); int carTankCapacity = int.Parse(carInfo[3]); double truckFuelConsumption = double.Parse(truckInfo[2]); double truckFuelQuantity = double.Parse(truckInfo[1]); int truckTankCapacity = int.Parse(truckInfo[3]); double busFuelConsumption = double.Parse(busInfo[2]); double busFuelQuantity = double.Parse(busInfo[1]); int busTankCapacity = int.Parse(busInfo[3]); Vehicle car = new Car(carFuelQuantity, carFuelConsumption, carTankCapacity); Vehicle truck = new Truck(truckFuelQuantity, truckFuelConsumption, truckTankCapacity); Bus bus = new Bus(busFuelQuantity, busFuelConsumption, busTankCapacity); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(); string command = input[0]; string vehicle = input[1]; try { if (command == "Drive") { if (vehicle == "Car") { car.Drive(double.Parse(input[2])); } else if (vehicle == "Truck") { truck.Drive(double.Parse(input[2])); } else if (vehicle == "Bus") { bus.DriveWithPeople(double.Parse(input[2])); } } else if (command == "Refuel") { if (vehicle == "Car") { car.Refuel(double.Parse(input[2])); } else if (vehicle == "Truck") { truck.Refuel(double.Parse(input[2])); } else if (vehicle == "Bus") { bus.Refuel(double.Parse(input[2])); } } else if (command == "DriveEmpty") { bus.Drive(double.Parse(input[2])); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
static void Main(string[] args) { //List<Vehicle> vehicles = new List<Vehicle>(); var carInput = Console.ReadLine().Split(" "); Vehicle car = new Car(double.Parse(carInput[1]), double.Parse(carInput[2]), double.Parse(carInput[3])); //vehicles.Add(car); var truckInput = Console.ReadLine().Split(" "); Vehicle truck = new Truck(double.Parse(truckInput[1]), double.Parse(truckInput[2]), double.Parse(truckInput[3])); //vehicles.Add(truck); var busInput = Console.ReadLine().Split(" "); Bus bus = new Bus(double.Parse(busInput[1]), double.Parse(busInput[2]), double.Parse(busInput[3])); int lines = int.Parse(Console.ReadLine()); for (int i = 0; i < lines; i++) { var command = Console.ReadLine().Split(" "); if (command[0] == "Drive" && command[1] == "Car") { car.Drive(double.Parse(command[2])); } if (command[0] == "Drive" && command[1] == "Truck") { truck.Drive(double.Parse(command[2])); } if (command[0] == "Drive" && command[1] == "Bus") { bus.DriveWithPeople(double.Parse(command[2])); } if (command[0] == "DriveEmpty" && command[1] == "Bus") { bus.Drive(double.Parse(command[2])); } if (command[0] == "Refuel" && command[1] == "Car") { car.Refuel(double.Parse(command[2])); } if (command[0] == "Refuel" && command[1] == "Truck") { truck.Refuel(double.Parse(command[2])); } if (command[0] == "Refuel" && command[1] == "Bus") { bus.Refuel(double.Parse(command[2])); } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:f2}"); }