public static void Main() { string[] carArgs = Console.ReadLine().Split(); double carFuelQuantity = double.Parse(carArgs[1]); double carFuelConsumption = double.Parse(carArgs[2]); Car car = new Car(carFuelQuantity, carFuelConsumption); string[] truckArgs = Console.ReadLine().Split(); double truckFuelQuantity = double.Parse(truckArgs[1]); double truckFuelConsumption = double.Parse(truckArgs[2]); Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption); int commandCount = int.Parse(Console.ReadLine()); for (int i = 0; i < commandCount; i++) { string[] commandArgs = Console.ReadLine().Split(); string command = commandArgs[0]; string commandType = commandArgs[1]; if (command == "Drive") { double distance = double.Parse(commandArgs[2]); if (commandType == "Car") { Console.WriteLine(car.Drive(distance)); } else { Console.WriteLine(truck.Drive(distance)); } } else { double fuelAmount = double.Parse(commandArgs[2]); if (commandType == "Car") { car.Refuel(fuelAmount); } else { truck.Refuel(fuelAmount); } } } Console.WriteLine(car); Console.WriteLine(truck); }
public static void Main() { string[] carInformation = Console.ReadLine().Split(); double carFuelQuantity = double.Parse(carInformation[1]); double carFuelConsumption = double.Parse(carInformation[2]); Car car = new Car(carFuelQuantity, carFuelConsumption); string[] truckInformation = Console.ReadLine().Split(); double truckFuelQuantity = double.Parse(truckInformation[1]); double truckFuelConsumption = double.Parse(truckInformation[2]); Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption); int numberOfCommand = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommand; i++) { string[] commandLine = Console.ReadLine().Split(); string command = commandLine[0]; string vehicle = commandLine[1]; double number = double.Parse(commandLine[2]); switch (command) { case "Drive": switch (vehicle) { case "Car": Console.WriteLine(car.Drive(number)); break; case "Truck": Console.WriteLine(truck.Drive(number)); break; } break; case "Refuel": switch (vehicle) { case "Car": car.AddFuel(number); break; case "Truck": truck.AddFuel(number); break; } break; } } Console.WriteLine(car); Console.WriteLine(truck); }
public static void Main() { string[] carInformation = Console.ReadLine().Split(); double carFuelQuantity = double.Parse(carInformation[1]); double carFuelConsumption = double.Parse(carInformation[2]); Car car = new Car(carFuelQuantity, carFuelConsumption); string[] truckInformation = Console.ReadLine().Split(); double truckFuelQuantity = double.Parse(truckInformation[1]); double truckFuelConsumption = double.Parse(truckInformation[2]); Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption); int numberOfCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommands; i++) { string[] input = Console.ReadLine().Split(); if (input[0] == "Drive") { double distance = double.Parse(input[2]); if (input[1] == "Car") { Console.WriteLine(car.Drive(distance)); } else if (input[1] == "Truck") { Console.WriteLine(truck.Drive(distance)); } } else if (input[0] == "Refuel") { double liters = double.Parse(input[2]); if (input[1] == "Car") { car.Refuel(liters); } else if (input[1] == "Truck") { truck.Refuel(liters); } } } Console.WriteLine(car); Console.WriteLine(truck); }
static void Main(string[] args) { var carInfo = Console.ReadLine().Split(); var carFuel = double.Parse(carInfo[1]); var carConsumption = double.Parse(carInfo[2]); var car = new Car(carFuel, carConsumption); var truckInfo = Console.ReadLine().Split(); var truckFuel = double.Parse(truckInfo[1]); var truckConsumption = double.Parse(truckInfo[2]); var truck = new Truck(truckFuel, truckConsumption); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var currentInput = Console.ReadLine().Split(); var command = currentInput[0]; var vehicle = currentInput[1]; if (command == "Drive") { var distance = double.Parse(currentInput[2]); if (vehicle == "Car") { Console.WriteLine(car.Drive(distance)); } else if (vehicle == "Truck") { Console.WriteLine(truck.Drive(distance)); } } else if (command == "Refuel") { var fuel = double.Parse(currentInput[2]); if (vehicle == "Car") { car.Refuel(fuel); } else if (vehicle == "Truck") { truck.Refuel(fuel); } } } Console.WriteLine(car); Console.WriteLine(truck); }
public static void Main() { var carInfo = Console.ReadLine().Split(); var fuelQuantity = double.Parse(carInfo[1]); var consumption = double.Parse(carInfo[2]); var tankCapacity = double.Parse(carInfo[3]); Car car = new Car(fuelQuantity, consumption, tankCapacity); var truckInfo = Console.ReadLine().Split(); fuelQuantity = double.Parse(truckInfo[1]); consumption = double.Parse(truckInfo[2]); tankCapacity = double.Parse(truckInfo[3]); Truck truck = new Truck(fuelQuantity, consumption, tankCapacity); var busInfo = Console.ReadLine().Split(); fuelQuantity = double.Parse(busInfo[1]); consumption = double.Parse(busInfo[2]); tankCapacity = double.Parse(busInfo[3]); Bus bus = new Bus(fuelQuantity, consumption, tankCapacity); var numberOfInputs = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfInputs; i++) { var input = Console.ReadLine().Split(); var command = input[0]; var vehicle = input[1]; if (command == "Drive") { var kmToDrive = double.Parse(input[2]); if (vehicle == "Car") { Console.WriteLine(car.Drive(kmToDrive));; } else if (vehicle == "Truck") { Console.WriteLine(truck.Drive(kmToDrive));; } else { Console.WriteLine(bus.Drive(kmToDrive)); } } else if (command == "DriveEmpty" && vehicle == "Bus") { var kmToDrive = double.Parse(input[2]); Console.WriteLine(bus.DriveEmpty(kmToDrive)); } else if (command == "Refuel") { var fuelAmount = double.Parse(input[2]); try { if (vehicle == "Car") { car.Refuel(fuelAmount); } else if (vehicle == "Truck") { truck.Refuel(fuelAmount); } else { bus.Refuel(fuelAmount); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
static void Main(string[] args) { string[] carInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); double carfuelQuantity = double.Parse(carInfo[1]); double carConsumption = double.Parse(carInfo[2]); double carTank = double.Parse(carInfo[3]); string[] truckInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); double truckFuelQuantity = double.Parse(truckInfo[1]); double truckConsumption = double.Parse(truckInfo[2]); double truckTank = double.Parse(truckInfo[3]); string[] busInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); double busFuelQuantity = double.Parse(busInfo[1]); double busConsumption = double.Parse(busInfo[2]); double busTank = double.Parse(busInfo[3]); Vehicle car = new Car(carfuelQuantity, carConsumption, carTank); Vehicle truck = new Truck(truckFuelQuantity, truckConsumption, truckTank); Bus bus = new Bus(busFuelQuantity, busConsumption, busTank); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] inputInfo = Console.ReadLine().Split(); string action = inputInfo[0]; string type = inputInfo[1]; if (action == "Drive") { double distance = double.Parse(inputInfo[2]); try { if (type == "Car") { Console.WriteLine(car.Drive(distance)); } else if (type == "Truck") { Console.WriteLine(truck.Drive(distance)); } else { Console.WriteLine(bus.Drive(distance)); } } catch (NotEnoughFuelException ex) { Console.WriteLine(ex.Message, type); } } else if (action == "DriveEmpty") { double distance = double.Parse(inputInfo[2]); try { Console.WriteLine(bus.DriveEmpty(distance)); } catch (NotEnoughFuelException ex) { Console.WriteLine(ex.Message, type); } } else if (action == "Refuel") { double liters = double.Parse(inputInfo[2]); try { if (type == "Car") { car.Refuel(liters); } else if (type == "Truck") { truck.Refuel(liters); } else { bus.Refuel(liters); } } catch (TankCapacityException ex) { Console.WriteLine(ex.Message, liters); } catch (FuelExcpetion fex) { Console.WriteLine(fex.Message); } } } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:F2}"); }
public static void Main() { var carInfo = Console.ReadLine().Split(); var truckInfo = Console.ReadLine().Split(); var busInfo = Console.ReadLine().Split(); IVehicle car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3])); IVehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3])); IVehicle bus = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3])); int lines = int.Parse(Console.ReadLine()); for (int i = 0; i < lines; i++) { string[] input = Console.ReadLine().Split(); string command = input[0]; string type = input[1]; double distance = double.Parse(input[2]); double litters = double.Parse(input[2]); try { if (command == "Drive") { if (type == "Car") { Console.WriteLine(car.Drive(distance)); } else if (type == "Truck") { Console.WriteLine(truck.Drive(distance)); } else if (type == "Bus") { bus.IsEmpty = false; Console.WriteLine(bus.Drive(distance)); } } else if (command == "DriveEmpty") { bus.IsEmpty = true; Console.WriteLine(bus.Drive(distance)); } else if (command == "Refuel") { if (type == "Car") { car.Refuel(litters); } else if (type == "Truck") { truck.Refuel(litters); } else if (type == "Bus") { bus.Refuel(litters); } } } catch (Exception ae) { Console.WriteLine(ae.Message); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }