public static void Main(string[] args) { string[] carTokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); string[] truckTokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); Vehicle car = new Car(double.Parse(carTokens[1]), double.Parse(carTokens[2])); Vehicle truck = new Truck(double.Parse(truckTokens[1]), double.Parse(truckTokens[2])); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); string command = input[0]; string vehicle = input[1]; double value = double.Parse(input[2]); if (command == "Drive") { if (vehicle == "Car") { car.Drive(value); } else { truck.Drive(value); } } else if (command == "Refuel") { if (vehicle == "Car") { car.Refuel(value); } else { truck.Refuel(value); } } } Console.WriteLine(car); Console.WriteLine(truck); }
public static void Main() { string[] firstLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double carFuelQuantity = double.Parse(firstLine[1]); double carFuelConsumtion = double.Parse(firstLine[2]); string[] secondLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double truckFuelQuantity = double.Parse(secondLine[1]); double truckFuelConsumption = double.Parse(secondLine[2]); Automobile car = new Car(carFuelQuantity, carFuelConsumtion); Automobile truck = new Truck(truckFuelQuantity, truckFuelConsumption); int lines = int.Parse(Console.ReadLine()); for (int i = 0; i < lines; i++) { string[] command = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double support = double.Parse(command[2]); //support refers to distance or litres if (command[1].Equals("Car")) { if (command[0].Equals("Drive")) { car.Drive(support); } else if (command[0].Equals("Refuel")) { car.Refuel(support); } } else if (command[1].Equals("Truck")) { if (command[0].Equals("Drive")) { truck.Drive(support); } else if (command[0].Equals("Refuel")) { truck.Refuel(support); } } } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); }
static void Main(string[] args) { var carInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); Vehicle car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2])); var truckInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); Vehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2])); var vechles = new List <Vehicle>(); vechles.Add(car); vechles.Add(truck); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var tokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); if (tokens[0] == "Drive") { if (tokens[1] == "Car") { car.Drive(double.Parse(tokens[2])); } else { truck.Drive(double.Parse(tokens[2])); } } else { if (tokens[1] == "Car") { car.Refuel(double.Parse(tokens[2])); } else { truck.Refuel(double.Parse(tokens[2])); } } } foreach (var vechle in vechles) { Console.WriteLine($"{vechle.GetType().Name}: {vechle.FuelQuantity:f2}"); } }
private static void ExecuteCommands(Car car, Truck truck) { var numberOfCommands = int.Parse(Console.ReadLine()); while (numberOfCommands > 0) { var command = Console.ReadLine().Split(); var action = command[0]; var vehicleType = command[1]; var value = double.Parse(command[2]); switch (action) { case "Drive": Console.WriteLine(vehicleType == "Car" ? car.Drive(value) : truck.Drive(value)); break; case "Refuel": switch (vehicleType) { case "Car": car.Refuel(value); break; case "Truck": truck.Refuel(value); break; default: break; } break; default: break; } numberOfCommands--; } }
public static void Main(string[] args) { string[] tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); IVehicle car = new Car(double.Parse(tokens[1]), double.Parse(tokens[2])); tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); IVehicle truck = new Truck(double.Parse(tokens[1]), double.Parse(tokens[2])); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); if (tokens[0] == "Drive") { if (tokens[1] == "Car") { Console.WriteLine(car.Drive(double.Parse(tokens[2]))); } else { Console.WriteLine(truck.Drive(double.Parse(tokens[2]))); } } else { if (tokens[1] == "Car") { car.Refuel(double.Parse(tokens[2])); } else { truck.Refuel(double.Parse(tokens[2])); } } } Console.WriteLine(car); Console.WriteLine(truck); }
static void Main(string[] args) { var carInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); var truckInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); var busInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); var carFuel = double.Parse(carInfo[1]); var carConsumption = double.Parse(carInfo[2]); var carCapacity = double.Parse(carInfo[3]); var theCar = new Car(carFuel, carConsumption, carCapacity); var truckFuel = double.Parse(truckInfo[1]); var truckConsumption = double.Parse(truckInfo[2]); var truckCapacity = double.Parse(truckInfo[3]); var theTruck = new Truck(truckFuel, truckConsumption, truckCapacity); var busFuel = double.Parse(busInfo[1]); var busConsumption = double.Parse(busInfo[2]); var busCapacity = double.Parse(busInfo[3]); var theBus = new Bus(busFuel, busConsumption, busCapacity); var numberOfCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommands; i++) { var command = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); var driveOrRefuel = command[0]; var carOrTruck = command[1]; var amout = double.Parse(command[2]); switch (carOrTruck) { case "Car": switch (driveOrRefuel) { case "Drive": theCar.Drive(amout); break; case "Refuel": theCar.Refuel(amout); break; } break; case "Truck": switch (driveOrRefuel) { case "Drive": theTruck.Drive(amout); break; case "Refuel": theTruck.Refuel(amout); break; } break; case "Bus": switch (driveOrRefuel) { case "Drive": theBus.Drive(amout); break; case "DriveEmpty": theBus.DriveEmpty(amout); break; case "Refuel": theBus.Refuel(amout); break; } break; } } Console.WriteLine($"Car: {theCar.FuelQuantity:f2}"); Console.WriteLine($"Truck: {theTruck.FuelQuantity:f2}"); Console.WriteLine($"Bus: {theBus.FuelQuantity:f2}"); }
static void Main(string[] args) { var carInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); Vehicle car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3])); var truckInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); Vehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3])); var busInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); Vehicle bus = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3])); var vechles = new List <Vehicle>() { car, truck, bus }; int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] vichlesTokens = Console.ReadLine().Split(' '); string cmd = vichlesTokens[0]; string vichles = vichlesTokens[1]; double quantity = double.Parse(vichlesTokens[2]); switch (vichles) { case "Car": if (cmd.Equals("Drive")) { car.Drive(quantity); } else { car.Refuel(quantity); } break; case "Truck": if (cmd.Equals("Drive")) { truck.Drive(quantity); } else { truck.Refuel(quantity); } break; case "Bus": if (cmd.Equals("Drive")) { bus.Drive(quantity); } else if (cmd.Equals("DriveEmpty")) { ((Bus)bus).DriveEmpty(quantity); } else { bus.Refuel(quantity); } break; } } foreach (var vechle in vechles) { Console.WriteLine($"{vechle.GetType().Name}: {vechle.FuelQuantity:f2}"); } }
static void Main(string[] args) { string car = Console.ReadLine(); string[] carInfo = car.Split(' ').ToArray(); Car currentCar = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3])); string truck = Console.ReadLine(); string[] truckInfo = truck.Split(' ').ToArray(); Truck currentTruck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3])); string bus = Console.ReadLine(); string[] busInfo = bus.Split(' ').ToArray(); Bus currentBus = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3])); int numberOfCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommands; i++) { string command = Console.ReadLine(); string[] commandInfo = command.Split(' ').ToArray(); if (commandInfo[1] == "Car") { if (commandInfo[0] == "Drive") { currentCar.Drive(double.Parse(commandInfo[2])); } else if (commandInfo[0] == "Refuel") { currentCar.Refuel(double.Parse(commandInfo[2])); } } else if (commandInfo[1] == "Truck") { if (commandInfo[0] == "Drive") { currentTruck.Drive(double.Parse(commandInfo[2])); } else if (commandInfo[0] == "Refuel") { currentTruck.Refuel(double.Parse(commandInfo[2])); } } else if (commandInfo[1] == "Bus") { if (commandInfo[0] == "Drive") { currentBus.Drive(double.Parse(commandInfo[2])); } else if (commandInfo[0] == "DriveEmpty") { currentBus.Drive(double.Parse(commandInfo[2])); } else if (commandInfo[0] == "Refuel") { currentBus.Refuel(double.Parse(commandInfo[2])); } } } Console.WriteLine($"{currentCar.FuelQuantity:f2}"); Console.WriteLine($"{currentTruck.FuelQuantity:f2}"); Console.WriteLine($"{currentBus.FuelQuantity:f2}"); }