static void Main(string[] args) { string[] input = Console.ReadLine().Split(); var car = new Car(double.Parse(input[1]), double.Parse(input[2]), double.Parse(input[3])); input = Console.ReadLine().Split(); var truck = new Truck(double.Parse(input[1]), double.Parse(input[2]), double.Parse(input[3])); input = Console.ReadLine().Split(); var bus = new Bus(double.Parse(input[1]), double.Parse(input[2]), double.Parse(input[3])); int numberOfLines = int.Parse(Console.ReadLine()); for (int counter = 0; counter < numberOfLines; counter++) { input = Console.ReadLine().Split(); double distancesOrQuantity = double.Parse(input[2]); if (input[0] == "Drive") { if (input[1] == "Car") { car.Drive(distancesOrQuantity); } else if (input[1] == "Truck") { truck.Drive(distancesOrQuantity); } else { bus.Drive(distancesOrQuantity); } } else if (input[0] == "Refuel") { if (input[1] == "Car") { car.Refuel(distancesOrQuantity); } else if (input[1] == "Truck") { truck.Refuel(distancesOrQuantity); } else { truck.Refuel(distancesOrQuantity); } } else { bus.DriveEmptyBus(distancesOrQuantity); } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:f2}"); }
static void Main(string[] args) { string[] carInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string[] truckInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); double carFuelQuantity = double.Parse(carInfo[1]); double carFuelConsumption = double.Parse(carInfo[2]); double truckFuelQuantity = double.Parse(truckInfo[1]); double truckFuelConsumption = double.Parse(truckInfo[2]); Vehicle car = new Car(carFuelQuantity, carFuelConsumption); Vehicle truck = new Truck(truckFuelQuantity, truckFuelConsumption); int numberOfOperations = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfOperations; i++) { string[] cmdArgs = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string option = cmdArgs[0]; string type = cmdArgs[1]; double amount = double.Parse(cmdArgs[2]); if (option == "Drive") { try { if (type == nameof(Car)) { car.Drive(amount); } else if (type == nameof(Truck)) { truck.Drive(amount); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } else if (option == "Refuel") { if (type == nameof(Car)) { car.Refuel(amount); } else if (type == nameof(Truck)) { truck.Refuel(amount); } } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); }
public static void Main(string[] args) { var line = Console.ReadLine().Split(); Vehicle car = new Car(double.Parse(line[1]), double.Parse(line[2])); var line2 = Console.ReadLine().Split(); Vehicle truck = new Truck(double.Parse(line2[1]), double.Parse(line2[2])); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var input = Console.ReadLine().Split(); if (input[0] == "Drive" && input[1] == "Car") { car.Travel(double.Parse(input[2]), "Car"); } if (input[0] == "Refuel" && input[1] == "Car") { car.Refuel(double.Parse(input[2])); } if (input[0] == "Drive" && input[1] == "Truck") { truck.Travel(double.Parse(input[2]), "Truck"); } if (input[0] == "Refuel" && input[1] == "Truck") { truck.Refuel(double.Parse(input[2])); } } Console.WriteLine($"Car: {car.FuelQuant:F2}"); Console.WriteLine($"Truck: {truck.FuelQuant:F2}"); }
private static void RefuelCommand(string[] commandParts) { string vehicle = commandParts[1]; switch (vehicle) { case "Car": car.Refuel(double.Parse(commandParts[2])); break; case "Truck": truck.Refuel(double.Parse(commandParts[2])); break; case "Bus": bus.Refuel(double.Parse(commandParts[2])); break; } }
private static void Main() { string[] carItems = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double carFuelQuantity = double.Parse(carItems[1]); double carFuelConsumption = double.Parse(carItems[2]); Car car = new Car(carFuelQuantity, carFuelConsumption); string[] truckItems = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double truckFuelQuantity = double.Parse(truckItems[1]); double truckFuelConsumption = double.Parse(truckItems[2]); Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption); int count = int.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { string[] commandItems = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string command = commandItems[0]; string type = commandItems[1]; if (command == "Drive") { double distance = double.Parse(commandItems[2]); if (type == "Car") { Console.WriteLine(car.Drive(distance)); } else { Console.WriteLine(truck.Drive(distance)); } } else if (command == "Refuel") { double fuel = double.Parse(commandItems[2]); if (type == "Car") { car.Refuel(fuel); } else { truck.Refuel(fuel); } } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); }
public void Run() { string[] carInfo = Console.ReadLine() .Split() .ToArray(); string[] truckInfo = Console.ReadLine() .Split() .ToArray(); double carFuelQuantity = double.Parse(carInfo[1]); double carFuelConsumption = double.Parse(carInfo[2]); double truckFuelQuantity = double.Parse(truckInfo[1]); double truckConsumption = double.Parse(truckInfo[2]); var car = new Car(carFuelQuantity, carFuelConsumption); var truck = new Truck(truckFuelQuantity, truckConsumption); int count = int.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { string[] inputInfo = Console.ReadLine() .Split() .ToArray(); string command = inputInfo[0]; string vehicleType = inputInfo[1]; double value = double.Parse(inputInfo[2]); if (command == "Drive") { if (vehicleType == "Car") { DriveVehicle(car, value); } else if (vehicleType == "Truck") { DriveVehicle(truck, value); } } else if (command == "Refuel") { if (vehicleType == "Car") { car.Refuel(value); } else if (vehicleType == "Truck") { truck.Refuel(value); } } } Console.WriteLine($"Car: {Math.Round(car.FuelQuantity, 2, MidpointRounding.ToEven):F2}"); Console.WriteLine($"Truck: {Math.Round(truck.FuelQuantity, 2, MidpointRounding.ToEven):F2}"); }
static void Main(string[] args) { string[] carTokens = Console.ReadLine().Split(); double fuelConsum = double.Parse(carTokens[2]); double fuelQuantity = double.Parse(carTokens[1]); Car car = new Car(carTokens[1], carTokens[2], carTokens[3]); string[] truckTokens = Console.ReadLine().Split(); Truck truck = new Truck(truckTokens[1], truckTokens[2], truckTokens[3]); string[] busTokens = Console.ReadLine().Split(); Bus bus = new Bus(busTokens[1], busTokens[2], busTokens[3]); int numberOfComands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfComands; i++) { string[] comand = Console.ReadLine().Split(); if (comand[0] == "Drive") { double distance = double.Parse(comand[2]); if (comand[1] == "Car") { car.Drive(distance); } else if (comand[1] == "Truck") { truck.Drive(distance); } else if (comand[1] == "Bus") { bus.DrivewithPassenger(distance); } } else if (comand[0] == "Refuel") { double quantity = double.Parse(comand[2]); if (comand[1] == "Car") { car.Refuel(quantity); } else if (comand[1] == "Truck") { truck.Refuel(quantity); } else if (comand[1] == "Bus") { bus.Refuel(quantity); } } else if (comand[0] == "DriveEmpty") { bus.DrivewithPassenger(double.Parse(comand[2])); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
public static void Main(string[] args) { List <Vehicle> vehicles = new List <Vehicle>(); //Car {fuel quantity} {liters per km} string[] carInfo = Console.ReadLine().Split(); double carFuelQuantity = double.Parse(carInfo[1]); double carLitersPerKm = double.Parse(carInfo[2]); Vehicle car = new Car(carFuelQuantity, carLitersPerKm); vehicles.Add(car); string[] truckInfo = Console.ReadLine().Split(); double truckFuelQuantity = double.Parse(truckInfo[1]); double truckLitersPerKm = double.Parse(truckInfo[2]); Vehicle truck = new Truck(truckFuelQuantity, truckLitersPerKm); vehicles.Add(truck); 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 distanceOrFuelNeeded = double.Parse(input[2]); if (command == "Drive") { if (vehicleType == "Car") { car.DistanceTravelled(distanceOrFuelNeeded); } else { truck.DistanceTravelled(distanceOrFuelNeeded); } } else if (command == "Refuel") { if (vehicleType == "Car") { car.Refuel(distanceOrFuelNeeded); } else { truck.Refuel(distanceOrFuelNeeded); } } } foreach (var vehicle in vehicles) { Console.WriteLine(vehicle.ToString()); } }
public void Run() { Car car = CreateCar(); Truck truck = CreateTruck(); int commandsCount = int.Parse(Console.ReadLine()); for (int i = 0; i < commandsCount; i++) { try { string[] commandArgs = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string command = commandArgs[0]; string vechicleType = commandArgs[1]; switch (command) { case "Drive": double distance = double.Parse(commandArgs[2]); if (vechicleType == "Car") { Console.WriteLine(car.Drive(distance)); } else if (vechicleType == "Truck") { Console.WriteLine(truck.Drive(distance)); } break; case "Refuel": double fuelAmount = double.Parse(commandArgs[2]); if (vechicleType == "Car") { car.Refuel(fuelAmount); } else if (vechicleType == "Truck") { truck.Refuel(fuelAmount); } break; } } catch (ArgumentException ae) { Console.WriteLine(ae.Message); continue; } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); }
static void Main(string[] args) { string[] tokens = Console.ReadLine().Split(); Car car = new Car(double.Parse(tokens[1]), double.Parse(tokens[2]), double.Parse(tokens[3])); tokens = Console.ReadLine().Split(); Truck truck = new Truck(double.Parse(tokens[1]), double.Parse(tokens[2]), double.Parse(tokens[3])); tokens = Console.ReadLine().Split(); Bus bus = new Bus(double.Parse(tokens[1]), double.Parse(tokens[2]), double.Parse(tokens[3])); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { tokens = Console.ReadLine().Split(); if (tokens[0] == "Drive") { if (tokens[1] == "Car") { Console.WriteLine(car.Drive(double.Parse(tokens[2]))); } else if (tokens[1] == "Truck") { Console.WriteLine(truck.Drive(double.Parse(tokens[2]))); } else { Console.WriteLine(bus.Drive(double.Parse(tokens[2]))); } } else if (tokens[0] == "Refuel") { if (tokens[1] == "Car") { car.Refuel(double.Parse(tokens[2])); } else if (tokens[1] == "Truck") { truck.Refuel(double.Parse(tokens[2])); } else { bus.Refuel(double.Parse(tokens[2])); } } else // DriveEmpty { Console.WriteLine(bus.DriveEmpty(double.Parse(tokens[2]))); } } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:F2}"); }
static void Main(string[] args) { string[] vechicleData = Console.ReadLine().Split(); Car car = new Car(double.Parse(vechicleData[1]), double.Parse(vechicleData[2]), double.Parse(vechicleData[3])); vechicleData = Console.ReadLine().Split(); Truck truck = new Truck(double.Parse(vechicleData[1]), double.Parse(vechicleData[2]), double.Parse(vechicleData[3])); vechicleData = Console.ReadLine().Split(); Bus bus = new Bus(double.Parse(vechicleData[1]), double.Parse(vechicleData[2]), double.Parse(vechicleData[3])); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(); if (input[0] == "Drive") { if (input[1] == nameof(Car)) { car.Drive(double.Parse(input[2])); } else if (input[1] == nameof(Truck)) { truck.Drive(double.Parse(input[2])); } else if (input[1] == nameof(Bus)) { bus.Drive(double.Parse(input[2])); } } else if (input[0] == "Refuel") { if (input[1] == nameof(Car)) { car.Refuel(double.Parse(input[2])); } else if (input[1] == nameof(Truck)) { truck.Refuel(double.Parse(input[2])); } else if (input[1] == nameof(Bus)) { bus.Refuel(double.Parse(input[2])); } } else if (input[0] == "DriveEmpty" && input[1] == nameof(Bus)) { bus.DriveEmpty(double.Parse(input[2])); } } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:F2}"); }
static void Main(string[] args) { var carInput = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); var truckInput = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); Vehicle car = new Car(double.Parse(carInput[1]), double.Parse(carInput[2])); Vehicle truck = new Truck(double.Parse(truckInput[1]), double.Parse(truckInput[2])); var n = int.Parse(Console.ReadLine()); while (n > 0) { var commands = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); switch (commands[0]) { case "Drive": switch (commands[1]) { case "Car": car.DriveDistance(double.Parse(commands[2])); break; case "Truck": truck.DriveDistance(double.Parse(commands[2])); break; default: break; } break; case "Refuel": switch (commands[1]) { case "Car": car.Refuel(double.Parse(commands[2])); break; case "Truck": truck.Refuel(double.Parse(commands[2])); break; default: break; } break; } n--; } Console.WriteLine(car); Console.WriteLine(truck); }
static void Main(string[] args) { string[] carArgs = Console.ReadLine().Split(); string[] truckArgs = Console.ReadLine().Split(); Vehicle car = new Car(double.Parse(carArgs[1]), double.Parse(carArgs[2])); Vehicle truck = new Truck(double.Parse(truckArgs[1]), double.Parse(truckArgs[2])); int numberOfCommands = int.Parse(Console.ReadLine()); for (int curr = 0; curr < numberOfCommands; curr++) { string[] inputArgs = Console.ReadLine().Split(); string command = inputArgs[0]; string vehicle = inputArgs[1]; double commandArg = double.Parse(inputArgs[2]); switch (command) { case "Drive": try { if (vehicle == "Car") { car.Drive(commandArg); Console.WriteLine($"Car travelled {commandArg} km"); } else if (vehicle == "Truck") { truck.Drive(commandArg); Console.WriteLine($"Truck travelled {commandArg} km"); } } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } break; case "Refuel": if (vehicle == "Car") { car.Refuel(commandArg); } else if (vehicle == "Truck") { truck.Refuel(commandArg); } break; default: break; } } Console.WriteLine(car); Console.WriteLine(truck); }
static void Main(string[] args) { var carInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); var carFuelQuantity = double.Parse(carInfo[1]); var carFuelConsumption = double.Parse(carInfo[2]); Car car = new Car(carInfo[0], carFuelQuantity, carFuelConsumption); var truckInfo = Console.ReadLine() .Split(" "); var truckFuelQuantity = double.Parse(truckInfo[1]); var truckFuelConsumption = double.Parse(truckInfo[2]); Truck truck = new Truck(truckInfo[0], truckFuelQuantity, truckFuelConsumption); var count = int.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { var infoLine = Console.ReadLine() .Split(" "); var command = infoLine[0]; var currentVehicle = infoLine[1]; var fuelOrDistance = double.Parse(infoLine[2]); if (command == "Drive") { if (currentVehicle == "Car") { car.Drive(fuelOrDistance); } else if (currentVehicle == "Truck") { truck.Drive(fuelOrDistance); } } else if (command == "Refuel") { if (currentVehicle == "Car") { car.Refuel(fuelOrDistance); } else if (currentVehicle == "Truck") { truck.Refuel(fuelOrDistance); } } } Console.WriteLine(car); Console.WriteLine(truck); }
public void Run() { string[] carInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); string[] truckInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); int commandsCount = int.Parse(Console.ReadLine()); Vehicle car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2])); Vehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2])); for (int i = 0; i < commandsCount; i++) { string[] command = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); string action = command[0]?.ToLower(); string vehicleType = command[1]?.ToLower(); double quantity = double.Parse(command[2]); switch (action) { case "drive": if (vehicleType == "car") { car.Drive(quantity); } else if (vehicleType == "truck") { truck.Drive(quantity); } break; case "refuel": if (vehicleType == "car") { car.Refuel(quantity); } else if (vehicleType == "truck") { truck.Refuel(quantity); } break; default: break; } } Console.WriteLine(car); Console.WriteLine(truck); }
public static void Main() { // "Car {fuel quantity} {liters per km}" string[] carInfoArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); var car = new Car(double.Parse(carInfoArgs[1]), double.Parse(carInfoArgs[2])); // "Truck {fuel quantity} {liters per km}" string[] truckInfoArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); var truck = new Truck(double.Parse(truckInfoArgs[1]), double.Parse(truckInfoArgs[2])); int N = int.Parse(Console.ReadLine()); for (int i = 0; i < N; i++) { // read cmds string[] cmdArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); if (cmdArgs[0] == "Drive") { try { double distance = double.Parse(cmdArgs[2]); if (cmdArgs[1] == "Car") { car.Drive(distance); } else if (cmdArgs[1] == "Truck") { truck.Drive(distance); } Console.WriteLine($"{cmdArgs[1]} travelled {distance} km"); } catch (ArgumentException ex) { Console.WriteLine(ex.Message);; } } else if (cmdArgs[0] == "Refuel") { double liters = double.Parse(cmdArgs[2]); if (cmdArgs[1] == "Car") { car.Refuel(liters); } else if (cmdArgs[1] == "Truck") { truck.Refuel(liters); } } } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); }
static void Main(string[] args) { string[] carInfo = Console.ReadLine().Split(); string[] truckInfo = Console.ReadLine().Split(); string[] busInfo = Console.ReadLine().Split(); int n = int.Parse(Console.ReadLine()); Vehicle car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3])); Vehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3])); Vehicle bus = new Truck(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3])); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(); string command = input[0]; string vehicle = input[1]; double distanceOrLitters = double.Parse(input[2]); switch (command) { case "Drive": Console.WriteLine(vehicle == "Car" ? car.Drive(distanceOrLitters) : truck.Drive(distanceOrLitters)); break; case "Refuel": switch (vehicle) { case "Car": car.Refuel(distanceOrLitters); break; case "Truck": truck.Refuel(distanceOrLitters); break; default: break; } break; default: break; } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); }
public static void Main(string[] args) { string[] firstInput = Console.ReadLine().Split(); double carFuelQuantity = double.Parse(firstInput[1]); double carFuelConsumption = double.Parse(firstInput[2]); string[] secondInput = Console.ReadLine().Split(); double truckFuelQuantity = double.Parse(secondInput[1]); double truckFuelConsumption = double.Parse(secondInput[2]); Car car = new Car(carFuelQuantity, carFuelConsumption); Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string input = Console.ReadLine(); string[] splitted = input.Split(); string command = splitted[0]; string vehicle = splitted[1]; if (command == "Drive") { double distance = double.Parse(splitted[2]); if (vehicle == "Car") { Console.WriteLine(car.Drive(distance)); } else if (vehicle == "Truck") { Console.WriteLine(truck.Drive(distance)); } } else if (command == "Refuel") { double liters = double.Parse(splitted[2]); if (vehicle == "Car") { car.Refuel(liters); } else if (vehicle == "Truck") { truck.Refuel(liters); } } } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); }
public static void Main(string[] args) { string inputCarInformation = Console.ReadLine(); var listOfCarInformation = inputCarInformation .Split(new[] { ' ' }) .ToList(); Car car = new Car(double.Parse(listOfCarInformation[1]), double.Parse(listOfCarInformation[2])); string inputTruckInformation = Console.ReadLine(); var listOfTruckInformation = inputTruckInformation .Split(new[] { ' ' }) .ToList(); Truck truck = new Truck(double.Parse(listOfTruckInformation[1]), double.Parse(listOfTruckInformation[2])); int repeat = int.Parse(Console.ReadLine()); for (int i = 0; i < repeat; i++) { string inputCommand = Console.ReadLine(); var vehicleCommand = inputCommand .Split(new[] { ' ' }) .ToList(); switch (vehicleCommand[0]) { case "Drive": if (vehicleCommand[1] == "Car") { Console.WriteLine(car.Drive(double.Parse(vehicleCommand[2])));; } else if (vehicleCommand[1] == "Truck") { Console.WriteLine(truck.Drive(double.Parse(vehicleCommand[2])));; } break; case "Refuel": if (vehicleCommand[1] == "Car") { car.Refuel(double.Parse(vehicleCommand[2])); } else if (vehicleCommand[1] == "Truck") { truck.Refuel(double.Parse(vehicleCommand[2])); } break; default: break; } } Console.WriteLine($"{car:f2}"); Console.WriteLine($"{truck:f2}"); }
public static void Main() { var carArgs = Console.ReadLine().Split(); var truckArgs = Console.ReadLine().Split(); int linesCount = int.Parse(Console.ReadLine()); var carFuelQuantity = double.Parse(carArgs[1]); var carFuelConsumption = double.Parse(carArgs[2]); var car = new Car(carFuelQuantity, carFuelConsumption); var truckFuelQuantity = double.Parse(truckArgs[1]); var truckFuelConsumption = double.Parse(truckArgs[2]); var truck = new Truck(truckFuelQuantity, truckFuelConsumption); for (int i = 0; i < linesCount; i++) { var commandArgs = Console.ReadLine().Split(); var command = commandArgs[0]; var type = commandArgs[1]; if (command == "Drive") { var distance = double.Parse(commandArgs[2]); if (type == "Car") { Console.WriteLine(car.Drive(distance)); } else { Console.WriteLine(truck.Drive(distance)); } } else if (command == "Refuel") { double fuel = double.Parse(commandArgs[2]); if (type == "Car") { car.Refuel(fuel); } else { truck.Refuel(fuel); } } } Console.WriteLine(car); Console.WriteLine(truck); }
static void Main(string[] args) { string[] carInput = Console.ReadLine().Split(); string[] truckInput = Console.ReadLine().Split(); double carFuelQuantity = double.Parse(carInput[1]); double carPerKm = double.Parse(carInput[2]); double truckFuelQuantity = double.Parse(truckInput[1]); double truckPerKm = double.Parse(truckInput[2]); int n = int.Parse(Console.ReadLine()); Car car = new Car(carFuelQuantity, carPerKm, 0.9); Truck truck = new Truck(truckFuelQuantity, truckPerKm, 1.6); for (int i = 0; i < n; i++) { string[] vehicleCommand = Console.ReadLine().Split(); string command = vehicleCommand[0]; string vehicleType = vehicleCommand[1]; double commandParam = double.Parse(vehicleCommand[2]); switch (command) { case "Drive": if (vehicleType == "Car") { car.Drive(commandParam); } else if (vehicleType == "Truck") { truck.Drive(commandParam); } break; case "Refuel": if (vehicleType == "Car") { car.Refuel(commandParam); } else if (vehicleType == "Truck") { truck.Refuel(commandParam); } break; } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); }
static void Main(string[] args) { var carInput = Console.ReadLine().Split(); Vehicle car = new Car( double.Parse(carInput[1]), double.Parse(carInput[2])); var truckInput = Console.ReadLine().Split(); Vehicle truck = new Truck( double.Parse(truckInput[1]), double.Parse(truckInput[2])); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var line = Console.ReadLine().Split(); var command = line[0]; var vehicle = line[1]; if (command == "Drive") { double distance = double.Parse(line[2]); if (vehicle == nameof(Car)) { Console.WriteLine(car.Drive(distance)); } else if (vehicle == nameof(Truck)) { Console.WriteLine(truck.Drive(distance)); } } else if (command == "Refuel") { double fuel = double.Parse(line[2]); if (vehicle == nameof(Car)) { car.Refuel(fuel); } else if (vehicle == nameof(Truck)) { truck.Refuel(fuel); } } } Console.WriteLine(car); Console.WriteLine(truck); }
private static void ParseCommand(string[] command, Car car, Bus bus, Truck truck) { string res = "Unknown command"; switch (command[0]) { case "Drive": { double.TryParse(command[2], out double distance); res = Drive(command[1], distance, car, bus, truck); Console.WriteLine(res); } break; case "DriveEmpty": { double.TryParse(command[2], out double distance); switch (command[1]) { case "Bus": res = bus.DriveEmpty(distance); break; default: res = "Only bus can be drivven empty."; break; } Console.WriteLine(res); } break; case "Refuel": { double.TryParse(command[2], out double liters); switch (command[1]) { case "Car": res = car.Refuel(liters); break; case "Truck": res = truck.Refuel(liters); break; case "Bus": res = bus.Refuel(liters); break; default: res = "Unknown vehicle"; break; } if (res != "") { Console.WriteLine(res); } } break; default: res = "unknown command"; break; } }
static void Main(string[] args) { string[] carData = Console.ReadLine() .Split(); //Car 15 0.3 Car car = new Car(double.Parse(carData[1]), double.Parse(carData[2])); string[] truckData = Console.ReadLine() .Split(); Truck truck = new Truck(double.Parse(truckData[1]), double.Parse(truckData[2])); int commandsCount = int.Parse(Console.ReadLine()); for (int i = 0; i < commandsCount; i++) { string[] currentCmd = Console.ReadLine() .Split(); string type = currentCmd[1]; string command = currentCmd[0]; double amount = double.Parse(currentCmd[2]); if (type == nameof(Car)) { if (command == "Drive") { Console.WriteLine(car.Drive(amount)); } else { car.Refuel(amount); } } else if (type == nameof(Truck)) { if (command == "Drive") { Console.WriteLine(truck.Drive(amount)); } else { truck.Refuel(amount); } } } Console.WriteLine(car); Console.WriteLine(truck); }
static void Main(string[] args) { string[] carInfo = ConsoleRead(); string[] truckInfo = ConsoleRead(); Car car = CreateCar(carInfo); Truck truck = CreateTruck(truckInfo); int numberofCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberofCommands; i++) { string[] commandInfo = ConsoleRead(); string command = commandInfo[0]; double distance = double.Parse(commandInfo[2]); double litres = double.Parse(commandInfo[2]); string type = commandInfo[1]; switch (command) { case "Drive": switch (type) { case "Car": car.Drive(distance); break; case "Truck": truck.Drive(distance); break; } break; case "Refuel": switch (type) { case "Car": car.Refuel(litres); break; case "Truck": truck.Refuel(litres); break; } break; } } Console.WriteLine(car); Console.WriteLine(truck); }
private static void RefuelVehicleCheck(Car car, Truck truck, string[] cmdInput, string type) { if (type == "Car") { double liters = double.Parse(cmdInput[2]); car.Refuel(liters); } else if (type == "Truck") { double liters = double.Parse(cmdInput[2]); truck.Refuel(liters); } }
static void Main(string[] args) { string[] carMetricks = Console.ReadLine().Split(); double fuelQuantity = double.Parse(carMetricks[1]); double litersPerKm = double.Parse(carMetricks[2]); Car car = new Car(fuelQuantity, litersPerKm); string[] truckMetricks = Console.ReadLine().Split(); fuelQuantity = double.Parse(truckMetricks[1]); litersPerKm = double.Parse(truckMetricks[2]); Truck truck = new Truck(fuelQuantity, litersPerKm); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] command = Console.ReadLine().Split(); switch (command[0]) { case "Drive": if (command[1] == "Car") { Console.WriteLine(car.Drive(double.Parse(command[2]))); } else { Console.WriteLine(truck.Drive(double.Parse(command[2]))); } break; case "Refuel": if (command[1] == "Car") { car.Refuel(double.Parse(command[2])); } else { truck.Refuel(double.Parse(command[2])); } break; } } Console.WriteLine(car); Console.WriteLine(truck); }
private static void ExecuteAction(Car car, Truck truck, Bus bus, string action, string vehicleType, double argument) { switch (action) { case "Drive": if (vehicleType == "Car") { Console.WriteLine(car.Drive(argument)); } else if (vehicleType == "Truck") { Console.WriteLine(truck.Drive(argument)); } else if (vehicleType == "Bus") { Console.WriteLine(bus.Drive(argument, Bus.increasedFuelConsumption)); } break; case "DriveEmpty": if (vehicleType == "Bus") { Console.WriteLine(bus.Drive(argument)); } break; case "Refuel": if (argument <= 0) { Console.WriteLine("Fuel must be a positive number"); } else { if (vehicleType == "Car") { car.Refuel(argument); } else if (vehicleType == "Truck") { truck.Refuel(argument); } else if (vehicleType == "Bus") { bus.Refuel(argument); } } break; } }
public static void Main() { string[] carArgs = Console.ReadLine() .Split(); string[] truckArgs = Console.ReadLine() .Split(); Car car = new Car(double.Parse(carArgs[1]), double.Parse(carArgs[2])); Truck truck = new Truck(double.Parse(truckArgs[1]), double.Parse(truckArgs[2])); int count = int.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { string[] inputArgs = Console.ReadLine() .Split(); string command = inputArgs[0]; string vehicleType = inputArgs[1]; double distanceOrLiters = double.Parse(inputArgs[2]); if (command == "Drive") { if (vehicleType == "Car") { Console.WriteLine(car.Drive(distanceOrLiters)); } else if (vehicleType == "Truck") { Console.WriteLine(truck.Drive(distanceOrLiters)); } } else if (command == "Refuel") { if (vehicleType == "Car") { car.Refuel(distanceOrLiters); } else if (vehicleType == "Truck") { truck.Refuel(distanceOrLiters); } } } Console.WriteLine(car); Console.WriteLine(truck); }
public void Run() { var carInfo = Console.ReadLine().Split(); var carFuelQuantity = double.Parse(carInfo[1]); var carLitersPerKm = double.Parse(carInfo[2]); var car = new Car(carFuelQuantity, carLitersPerKm); var truckInfo = Console.ReadLine().Split(); var truckFuelQuantity = double.Parse(truckInfo[1]); var truckLitersPerKm = double.Parse(truckInfo[2]); var truck = new Truck(truckFuelQuantity, truckLitersPerKm); var counter = int.Parse(Console.ReadLine()); for (int i = 0; i < counter; i++) { var command = Console.ReadLine().Split(); if (command[0] == "End") { break; } else if (command[0] == "Drive" && command[1] == "Car") { var kilometersToDrive = double.Parse(command[2]); car.Drive(kilometersToDrive); } else if (command[0] == "Refuel" && command[1] == "Car") { var fuel = double.Parse(command[2]); car.Refuel(fuel); } else if (command[0] == "Drive" && command[1] == "Truck") { var kilometersToDrive = double.Parse(command[2]); truck.Drive(kilometersToDrive); } else if (command[0] == "Refuel" && command[1] == "Truck") { var fuel = double.Parse(command[2]); truck.Refuel(fuel); } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); }