static void Main() { var carInput = Console.ReadLine().Split(); var truckInput = Console.ReadLine().Split(); var busInput = Console.ReadLine().Split(); Vehicle car = new Car(double.Parse(carInput[1]), double.Parse(carInput[2]), double.Parse(carInput[3])); Vehicle truck = new Truck(double.Parse(truckInput[1]), double.Parse(truckInput[2]), double.Parse(truckInput[3])); Bus bus = new Bus(double.Parse(busInput[1]), double.Parse(busInput[2]), double.Parse(busInput[3])); int numberOfCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommands; i++) { var command = Console.ReadLine().Split(); if (command[0].StartsWith('D')) { if (command[0] == "DriveEmpty") { bus.DriveEmpty(double.Parse(command[2])); } else { if (command[1].StartsWith('C')) { car.Drive(double.Parse(command[2])); } else if (command[1].StartsWith('T')) { truck.Drive(double.Parse(command[2])); } else if (command[1].StartsWith('B')) { bus.Drive(double.Parse(command[2])); } } } else if (command[0].StartsWith('R')) { if (command[1].StartsWith('C')) { car.Refuel(double.Parse(command[2])); } else if (command[1].StartsWith('T')) { truck.Refuel(double.Parse(command[2])); } else if (command[1].StartsWith('B')) { bus.Refuel(double.Parse(command[2])); } } } Console.WriteLine($"Car: {car.fuelQuantity:f2}\nTruck: {truck.fuelQuantity:f2}\nBus: {bus.fuelQuantity:f2}"); }
private static void Execution(Car car, Truck truck, Bus bus, int n) { for (int i = 0; i < n; i++) { string[] commands = Console.ReadLine().Split(); string command = commands[0]; string typeVehicle = commands[1]; if (command == "Drive") { double distance = double.Parse(commands[2]); if (typeVehicle == "Car") { Console.WriteLine(car.Drive(distance)); } else if (typeVehicle == "Truck") { Console.WriteLine(truck.Drive(distance)); } else { Console.WriteLine(bus.Drive(distance)); } } else if (command == "Refuel") { try { double refuelQuantity = double.Parse(commands[2]); if (typeVehicle == "Car") { car.Refuel(refuelQuantity); } else if (typeVehicle == "Truck") { truck.Refuel(refuelQuantity); } else { bus.Refuel(refuelQuantity); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { double distance = double.Parse(commands[2]); Console.WriteLine(bus.DriveEmpty(distance)); } } }
private static void ApplyChanges(Vehicle car, Vehicle truck, Bus bus, string cmdType, string whatToGet, double distance) { if (cmdType == "Drive") { if (whatToGet == "Car") { Console.WriteLine(car.Drive(distance)); } else if (whatToGet == "Truck") { Console.WriteLine(truck.Drive(distance)); } else if (whatToGet == "Bus") { Console.WriteLine(bus.Drive(distance)); } } else if (cmdType == "Refuel") { var amount = distance; if (whatToGet == "Car") { car.Refuel(amount); } else if (whatToGet == "Truck") { truck.Refuel(amount); } else if (whatToGet == "Bus") { bus.Refuel(amount); } } else if (cmdType == "DriveEmpty") { Console.WriteLine(bus.DriveEmpty(distance)); } }
static void Main(string[] args) { string[] carInput = Console.ReadLine().Split(); Car car = new Car( double.Parse(carInput[1]), double.Parse(carInput[2]), double.Parse(carInput[3])); string[] truckInput = Console.ReadLine().Split(); Truck truck = new Truck( double.Parse(truckInput[1]), double.Parse(truckInput[2]), double.Parse(truckInput[3])); string[] busInput = Console.ReadLine().Split(); Bus bus = new Bus( double.Parse(busInput[1]), double.Parse(busInput[2]), double.Parse(busInput[3])); int inputs = int.Parse(Console.ReadLine()); for (int i = 0; i < inputs; i++) { string[] input = Console.ReadLine().Split(); if (input[0] == "DriveEmpty") { bus.DriveEmpty(double.Parse(input[2])); } if (input[0] == "Drive") { if (input[1] == "Car") { car.Drive(double.Parse(input[2])); } else if (input[1] == "Truck") { truck.Drive(double.Parse(input[2])); } else if (input[1] == "Bus") { bus.Drive(double.Parse(input[2])); } } if (input[0] == "Refuel") { if (input[1] == "Car") { car.Refuel(double.Parse(input[2])); } else if (input[1] == "Truck") { truck.Refuel(double.Parse(input[2])); } else if (input[1] == "Bus") { bus.Refuel(double.Parse(input[2])); } } } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:F2}"); }
public static void Main() { string[] line1 = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string[] line2 = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string[] line3 = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int n = int.Parse(Console.ReadLine()); Car car = new Car(double.Parse(line1[1]), (double.Parse(line1[2]) + 0.9), double.Parse(line1[3])); Truck truck = new Truck(double.Parse(line2[1]), (double.Parse(line2[2]) + 1.6), double.Parse(line2[3])); Bus bus = new Bus(double.Parse(line3[1]), (double.Parse(line3[2]) + 1.4), double.Parse(line3[3])); for (int i = 0; i < n; i++) { try { string[] input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string command = input[0]; string typeVehicle = input[1]; double distanceOrLiters = double.Parse(input[2]); switch (command) { case "Drive": if (typeVehicle == "Car") { car.Drive(distanceOrLiters); } else if (typeVehicle == "Truck") { truck.Drive(distanceOrLiters); } else if (typeVehicle == "Bus") { bus.Drive(distanceOrLiters); } break; case "Refuel": if (typeVehicle == "Car") { car.Refuel(distanceOrLiters); } else if (typeVehicle == "Truck") { truck.Refuel(distanceOrLiters); } else if (typeVehicle == "Bus") { bus.Refuel(distanceOrLiters); } break; case "DriveEmpty": bus.DriveEmpty(distanceOrLiters); break; default: break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
static void Main() { try { var carInfo = Console.ReadLine().Split(); var carFuel = double.Parse(carInfo[1]); var carLitersPerKm = double.Parse(carInfo[2]); var carTank = double.Parse(carInfo[3]); var car = new Car(carFuel, carLitersPerKm, carTank); var truckInfo = Console.ReadLine().Split(); var truckFuel = double.Parse(truckInfo[1]); var truckLitersPerKm = double.Parse(truckInfo[2]); var truckTank = double.Parse(truckInfo[3]); var truck = new Truck(truckFuel, truckLitersPerKm, truckTank); var busInfo = Console.ReadLine().Split(); var busFuel = double.Parse(busInfo[1]); var busLitersPerKm = double.Parse(busInfo[2]); var busTank = double.Parse(busInfo[3]); var bus = new Bus(busFuel, busLitersPerKm, busTank); var commands = int.Parse(Console.ReadLine()); for (int i = 0; i < commands; i++) { var command = Console.ReadLine().Split(); var action = command[0]; var vehicleType = command[1]; var value = double.Parse(command[2]); switch (action) { case "Drive": switch (vehicleType) { case "Car": car.Drive(value); break; case "Truck": truck.Drive(value); break; case "Bus": bus.Drive(value); break; } break; case "Refuel": switch (vehicleType) { case "Car": car.Refuel(value); break; case "Truck": truck.Refuel(value); break; case "Bus": bus.Refuel(value); break; } break; case "DriveEmpty": bus.DriveEmpty(value); break; } } Console.WriteLine($"Car: {car.Fuel:f2}"); Console.WriteLine($"Truck: {truck.Fuel:f2}"); Console.WriteLine($"Bus: {bus.Fuel:f2}"); } catch (ArgumentException e) { Console.WriteLine(e.Message); throw; } }