private static void ExecuteCommand(Vehicle vehicle, string command, double value) { switch (command) { case "Drive": Console.WriteLine(vehicle.Drive(value)); break; case "Refuel": try { vehicle.Refuel(value); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } break; case "DriveEmpty": ((Bus)vehicle).SwitchOffAirConditioner(); Console.WriteLine(vehicle.Drive(value)); ((Bus)vehicle).SwitchOnAirConditioner(); break; } }
private static void ExecuteCommand(Vehicle vehicle, string command, double value) { switch (command) { case "Drive": Console.WriteLine(vehicle.Drive(value)); break; case "Refuel": try { vehicle.Refuel(value); } catch (ArgumentException e) { Console.WriteLine(e.Message); } break; case "DriveEmpty": var bus = vehicle as Bus; Console.WriteLine(bus.DriveEmpty(value)); break; } }
private static void ParseCommand(Vehicle car, Vehicle truck) { string[] commandArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).ToArray(); string command = commandArgs[0]; string vehicleType = commandArgs[1]; double thirdParameter = double.Parse(commandArgs[2]); if (command == "Drive") { if (vehicleType == "Car") { car.Drive(thirdParameter); Console.WriteLine($"Car travelled {thirdParameter} km"); } else if (vehicleType == "Truck") { truck.Drive(thirdParameter); Console.WriteLine($"Truck travelled {thirdParameter} km"); } } else if (command == "Refuel") { if (vehicleType == "Car") { car.Refuel(thirdParameter); } else if (vehicleType == "Truck") { truck.Refuel(thirdParameter); } } }
static void Main(string[] args) { List <Vehicle> vehicles = new List <Vehicle>(); for (int i = 0; i < 3; i++) { string[] cmdArgs = Console.ReadLine().Split(); string type = cmdArgs[0]; double liters = double.Parse(cmdArgs[1]); double consumption = double.Parse(cmdArgs[2]); double tankCapacity = double.Parse(cmdArgs[3]); Vehicle vehicle; if (type == "Car") { vehicle = new Car(liters, consumption, tankCapacity); } else if (type == "Truck") { vehicle = new Truck(liters, consumption, tankCapacity); } else { vehicle = new Bus(liters, consumption, tankCapacity); } vehicles.Add(vehicle); } int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] cmdArgs = Console.ReadLine().Split(); string command = cmdArgs[0]; string type = cmdArgs[1]; double argument = double.Parse(cmdArgs[2]); Vehicle vehicle = vehicles.FirstOrDefault(v => v.GetType().Name == type); if (command == "Drive") { vehicle.Drive(argument); } else if (command == "DriveEmpty") { ((Bus)vehicle).DriveEmpty(argument); } else { vehicle.Refuel(argument); } } vehicles.ForEach(v => Console.WriteLine(v)); }
static void Operate(Vehicle vehicle, string operation, double amaunt) { if (operation == "Drive") { vehicle.Drive(amaunt); } else if (operation == "Refuel") { vehicle.Refuel(amaunt); } }
private static void driveOrRefuel(string action, string litersOrDistance, Vehicle vehicle) { if (action == "Drive") { Console.WriteLine(vehicle.Drive(double.Parse(litersOrDistance))); } else { vehicle.Refuel(double.Parse(litersOrDistance)); } }
static void Action(Vehicle vehicle, string command, double distanceOrFuel) { if (command == "Drive") { Print(vehicle.Drive(distanceOrFuel)); } else { vehicle.Refuel(distanceOrFuel); } }
public static void ImplementationCommand(Vehicle vehicle, string action, double value) { if (action == "Drive") { Console.WriteLine(vehicle.Drive(value)); } else if (action == "Refuel") { vehicle.Refuel(value); } }
private static void ExecuteCommand(Vehicle vehicle, string command, double amount) { if (command == "Drive") { Console.WriteLine(vehicle.Drive(amount)); } else if (command == "Refuel") { vehicle.Refuel(amount); } }
public static void Main(string[] args) { Vehicle car = CreateVehicle(); Vehicle truck = CreateVehicle(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] inputData = Console.ReadLine().Split().ToArray(); string command = inputData[0]; string vehicleType = inputData[1]; if (command == "Drive") { double distance = double.Parse(inputData[2]); try { if (vehicleType == nameof(Car)) { car.Drive(distance); } else if (vehicleType == nameof(Truck)) { truck.Drive(distance); } Console.WriteLine($"{vehicleType} travelled {distance} km"); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } } else if (command == "Refuel") { double amount = double.Parse(inputData[2]); if (vehicleType == nameof(Car)) { car.Refuel(amount); } else if (vehicleType == nameof(Truck)) { truck.Refuel(amount); } } } Console.WriteLine(car); Console.WriteLine(truck); }
private static void DriveOrRefuel(Vehicle vehicle, string command, double parameter) { if (command.Equals("Drive")) { string result = vehicle.TryTravel(parameter); Console.WriteLine(result); } else { vehicle.Refuel(parameter); } }
private static void ExecuteCommand(Vehicle vehicle, string command, double value) { switch (command) { case "Drive": Console.WriteLine(vehicle.Drive(value)); break; case "Refuel": vehicle.Refuel(value); break; } }
static void Main(string[] args) { Vehicle car = createVehicle(); Vehicle truck = createVehicle(); int numberOfCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommands; i++) { string[] commandInfo = Console.ReadLine().Split(); string command = commandInfo[0]; string type = commandInfo[1]; double parameter = double.Parse(commandInfo[2]); if (command == "Drive") { try { if (type == nameof(Car)) { car.Drive(parameter); } else if (type == nameof(Truck)) { truck.Drive(parameter); } Console.WriteLine($"{type} travelled {parameter} km"); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } } else if (command == "Refuel") { if (type == nameof(Car)) { car.Refuel(parameter); } else if (type == nameof(Truck)) { truck.Refuel(parameter); } } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); }
private static void ExecuteAction(Vehicle vehicle, string command, double parameter) { switch (command) { case "Drive": var result = vehicle.TryTravelDistance(parameter); Console.WriteLine(result); break; case "Refuel": vehicle.Refuel(parameter); break; } }
static void Main(string[] args) { Vehicle car = CreateVehice(); Vehicle truck = CreateVehice(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(); string command = input[0]; string vehicleType = input[1]; double parameter = double.Parse(input[2]); if (command == "Drive") { try { if (vehicleType == nameof(Car)) { car.DriveDistance(parameter); } else { truck.DriveDistance(parameter); } Console.WriteLine($"{vehicleType} travelled {parameter} km"); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } } else { if (vehicleType == nameof(Car)) { car.Refuel(parameter); } else { truck.Refuel(parameter); } } } Console.WriteLine(car); Console.WriteLine(truck); }
private void ExecuteCommand(string command, double value, Vehicle vehicle) { if (command == "Drive") { vehicle.Drive(value); } else if (command == "Refuel") { vehicle.Refuel(value); } else if (command == "DriveEmpty") { ((Bus)vehicle).DriveEmpty(value); } }
public static void Main() { string[] carInfo = Console.ReadLine().Split(); string[] truckInfo = Console.ReadLine().Split(); Vehicle car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2])); Vehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2])); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Split(); string action = line[0]; string targetName = line[1]; double amount = double.Parse(line[2]); Vehicle target = null; if (targetName == "Car") { target = car; } else if (targetName == "Truck") { target = truck; } if (action == "Drive") { if (target.Drive(amount)) { Console.WriteLine($"{targetName} travelled {amount} km"); } else { Console.WriteLine($"{targetName} needs refueling"); } } else if (action == "Refuel") { target.Refuel(amount); } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); }
private static void VehicleAction(string[] cmdArgs, Vehicle vehicle) { if (cmdArgs[0] == "Drive") { Console.WriteLine(vehicle.Drive(double.Parse(cmdArgs[2]), vehicle.AcFuelIncrease)); } else if (cmdArgs[0] == "Refuel") { vehicle.Refuel(double.Parse(cmdArgs[2])); } else if (cmdArgs[0] == "DriveEmpty") { vehicle.IsAcTurnedOn = false; Console.WriteLine(vehicle.Drive(double.Parse(cmdArgs[2]), vehicle.AcFuelIncrease)); } }
private static void DoTheAction(Vehicle vehicle, string action, string vecihleType, double amount) { if (action == "DriveEmpty") { vehicle.IsEmpty = true; Console.WriteLine(vehicle.Drive(amount)); } else if (action == "Drive") { Console.WriteLine(vehicle.Drive(amount)); } else { vehicle.Refuel(amount); } }
private static void ProcessCommand(Vehicle vehicle, string command, double ammount) { if (command == "Drive") { vehicle.Drive(ammount); Console.WriteLine($"{vehicle.GetType().Name} travelled {ammount} km"); } else if (command == "DriveEmpty") { ((Bus)vehicle).DriveEmpty(ammount); // to do ako gramne ne setva off na AirCond Console.WriteLine($"{vehicle.GetType().Name} travelled {ammount} km"); } else if (command == "Refuel") { vehicle.Refuel(ammount); } }
private static void ExecuteCommand(Vehicle vehicle, string command, double d) { switch (command) { case "Drive": Console.WriteLine(vehicle.TryTravel(d)); break; case "Refuel": vehicle.Refuel(d); break; case "DriveEmpty": Console.WriteLine(vehicle.TryTravel(d, false)); break; } }
public void Run() { Vehicle car = SettingVehicleType(); Vehicle truck = SettingVehicleType(); int n = int.Parse(reader.ReadLine()); for (int i = 0; i < n; i++) { string[] cmdArgs = reader.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string action = cmdArgs[0]; string vecihleType = cmdArgs[1]; double amount = double.Parse(cmdArgs[2]); if (action == "Drive") { if (vecihleType == "Car") { Console.WriteLine(car.Drive(amount)); } else { Console.WriteLine(truck.Drive(amount)); } } else { if (vecihleType == "Car") { car.Refuel(amount); } else { truck.Refuel(amount); } } } writer.WriteLine(car.ToString()); writer.WriteLine(truck.ToString()); }
static void Main(string[] args) { Vehicle car = CreateVehicle(); Vehicle truck = CreateVehicle(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] cmdArg = Console.ReadLine().Split(); string command = cmdArg[0]; string type = cmdArg[1]; double distance = double.Parse(cmdArg[2]); if (command == "Drive") { if (type == typeof(Car).Name) { car.Drive(distance); } else { truck.Drive(distance); } } else if (command == "Refuel") { if (type == typeof(Car).Name) { car.Refuel(distance); } else { truck.Refuel(distance); } } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); }
private static void driveOrRefuel(string action, string litersOrDistance, Vehicle vehicle) { try { if (action == "Drive") { Console.WriteLine(vehicle.TryTravelDistance(double.Parse(litersOrDistance))); } else if (action == "Refuel") { vehicle.Refuel(double.Parse(litersOrDistance)); } else if (action == "DriveEmpty") { vehicle.TryTravelDistance(double.Parse(litersOrDistance), false); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static void ProcessCommand(Vehicle vehicle, string command, double parameter) { if (command == "Drive") { vehicle.Drive(parameter); Console.WriteLine($"{vehicle.GetType().Name} travelled {parameter} km"); } else if (command == "DriveEmpty") { ((Bus)vehicle).TurnOffAirCondition(); vehicle.Drive(parameter); ((Bus)vehicle).TurnOnAirCondition(); Console.WriteLine($"{vehicle.GetType().Name} travelled {parameter} km"); } else { vehicle.Refuel(parameter); } }
private static void MakeAction(Vehicle vehicle, string command, double parameter) { try { if (command == "Drive") { vehicle.Drive(parameter); } else if (command == "Refuel") { vehicle.Refuel(parameter); } else if (command == "DriveEmpty") { ((Bus)vehicle).ATurnOffAirConditioner(); vehicle.Drive(parameter); ((Bus)vehicle).TurnOnAirConditioner(); } } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { List <Vehicle> vehicles = new List <Vehicle>(); for (int i = 1; i <= 3; i++) { string[] vehicleArgs = Console.ReadLine().Split(); double fuelQuantity = double.Parse(vehicleArgs[1]); double fuelConsumtion = double.Parse(vehicleArgs[2]); int tanckCapacity = int.Parse(vehicleArgs[3]); Vehicle vehicle = null; if (i == 1) { vehicle = new Car(fuelQuantity, fuelConsumtion, tanckCapacity); } else if (i == 2) { vehicle = new Truck(fuelQuantity, fuelConsumtion, tanckCapacity); } else if (i == 3) { vehicle = new Bus(fuelQuantity, fuelConsumtion, tanckCapacity); } vehicles.Add(vehicle); } int commandCount = int.Parse(Console.ReadLine()); for (int i = 0; i < commandCount; i++) { string[] commandArgs = Console.ReadLine().Split(); string command = commandArgs[0]; string type = commandArgs[1]; if (command == "Drive") { double distance = double.Parse(commandArgs[2]); Vehicle vehicle = vehicles.FirstOrDefault(x => x.GetType().Name == type); Console.WriteLine(vehicle.Drive(distance)); } else if (command == "Refuel") { double fuelAmount = double.Parse(commandArgs[2]); Vehicle vehicle = vehicles.FirstOrDefault(x => x.GetType().Name == type); try { vehicle.Refuel(fuelAmount); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { double distance = double.Parse(commandArgs[2]); Bus vehicle = (Bus)vehicles.FirstOrDefault(x => x.GetType().Name == type); Console.WriteLine(vehicle.DriveEmpty(distance)); } } Console.WriteLine(string.Join(Environment.NewLine, vehicles)); }
private static void Refuel(Vehicle vehicle, double liters) { vehicle.Refuel(liters); }