public static void DriveEmpty(Bus bus, double distance) { try { bus.DriveEmpty(distance); } catch (ArgumentException e) { Console.WriteLine(e.Message); } }
private static void ParseCommand(int numberOfCommands) { for (int i = 0; i < numberOfCommands; i++) { string[] commandParts = Console.ReadLine().Split(' '); string command = commandParts[0]; switch (command) { case "Drive": DriveCommand(commandParts); break; case "Refuel": RefuelCommand(commandParts); break; case "DriveEmpty": _bus.DriveEmpty(double.Parse(commandParts[2])); break; } } }
private static void Main() { string[] carItems = Console.ReadLine().Split(); double carFuelQuantity = double.Parse(carItems[1]); double carLitersPerKilometer = double.Parse(carItems[2]); double carTankCapacity = double.Parse(carItems[3]); Car car = new Car(carFuelQuantity, carLitersPerKilometer, carTankCapacity); string[] truckItems = Console.ReadLine().Split(); double truckFuelQuantity = double.Parse(truckItems[1]); double truckLitersPerKilometer = double.Parse(truckItems[2]); double truckTankCapacity = double.Parse(truckItems[3]); Truck truck = new Truck(truckFuelQuantity, truckLitersPerKilometer, truckTankCapacity); string[] busItems = Console.ReadLine().Split(); double busFuelQuantity = double.Parse(busItems[1]); double busLitersPerKilometer = double.Parse(busItems[2]); double busTankCapacity = double.Parse(truckItems[3]); Bus bus = new Bus(busFuelQuantity, busLitersPerKilometer, busTankCapacity); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] lineItems = Console.ReadLine().Split(); string command = lineItems[0]; string vehicle = lineItems[1]; if (command == "Drive") { if (vehicle == "Car") { car.FuelQuantity = car.DriveCar(double.Parse(lineItems[2])); } if (vehicle == "Truck") { truck.FuelQuantity = truck.DriveTruck(double.Parse(lineItems[2])); } if (vehicle == "Bus") { bus.FuelQuantity = bus.DriveBus(double.Parse(lineItems[2])); } } if (command == "Refuel") { if (vehicle == "Car") { car.FuelQuantity = car.RefuelCar(double.Parse(lineItems[2])); } if (vehicle == "Truck") { truck.FuelQuantity = truck.RefuelTruck(double.Parse(lineItems[2])); } if (vehicle == "Bus") { bus.FuelQuantity = bus.RefuelBus(double.Parse(lineItems[2])); } } if (command == "DriveEmpty") { bus.FuelQuantity = bus.DriveEmpty(double.Parse(lineItems[2])); } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); Console.WriteLine(bus.ToString()); }
static void Main() { string[] carInfo = Console.ReadLine().Split(); string[] truckInfo = Console.ReadLine().Split(); string[] busInfo = Console.ReadLine().Split(); double carFuelQuantity = double.Parse(carInfo[1]); double carFuelConsumtion = double.Parse(carInfo[2]); double carTankCapacity = double.Parse(carInfo[3]); double truckFuelQuantity = double.Parse(truckInfo[1]); double truckFuelConsumtion = double.Parse(truckInfo[2]); double truckTankCapacity = double.Parse(truckInfo[3]); double busFuelQuantity = double.Parse(busInfo[1]); double busFuelConsumtion = double.Parse(busInfo[2]); double busTankCapacity = double.Parse(busInfo[3]); Vehicle car = new Car(carFuelQuantity, carFuelConsumtion, carTankCapacity); Vehicle truck = new Truck(truckFuelQuantity, truckFuelConsumtion, truckTankCapacity); Bus bus = new Bus(busFuelQuantity, busFuelConsumtion, busTankCapacity); int rotations = int.Parse(Console.ReadLine()); for (int i = 0; i < rotations; i++) { string[] commandArgs = Console.ReadLine().Split(); string command = commandArgs[0]; string vehicleType = commandArgs[1]; string value = commandArgs[2]; if (command == "Drive") { double distance = double.Parse(value); if (vehicleType == "Car") { Console.WriteLine(car.Drive(distance)); } else if (vehicleType == "Truck") { Console.WriteLine(truck.Drive(distance)); } else if (vehicleType == "Bus") { Console.WriteLine(bus.Drive(distance)); } } else if (command == "DriveEmpty") { double distance = double.Parse(value); Console.WriteLine(bus.DriveEmpty(distance)); } try { if (command == "Refuel") { double fuel = double.Parse(value); if (vehicleType == "Car") { car.Refuel(fuel); } else if (vehicleType == "Truck") { truck.Refuel(fuel); } else if (vehicleType == "Bus") { bus.Refuel(fuel); } } } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
static void Main(string[] args) { string[] carInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string[] truckInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string[] busInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); Car car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3])); Truck truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3])); Bus bus = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3])); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] commandElements = Console.ReadLine() .Split(" "); switch (commandElements[0]) { case "Drive": double distance = double.Parse(commandElements[2]); switch (commandElements[1]) { case "Car": car.Drive(distance); break; case "Truck": truck.Drive(distance); break; case "Bus": bus.Drive(distance); break; } break; case "DriveEmpty": bus.DriveEmpty(double.Parse(commandElements[2])); break; case "Refuel": double fuelLiters = double.Parse(commandElements[2]); switch (commandElements[1]) { case "Car": car.Refuel(fuelLiters); break; case "Truck": truck.Refuel(fuelLiters); break; case "Bus": bus.Refuel(fuelLiters); break; } break; } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
public static void Main() { string input = Console.ReadLine(); List <Vehicle> vehicles = new List <Vehicle>(); string[] carDetails = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double carFuel = double.Parse(carDetails[1]); double carConsumption = double.Parse(carDetails[2]); double carTankCapacity = double.Parse(carDetails[3]); Vehicle car = new Car(carFuel, carConsumption, carTankCapacity); vehicles.Add(car); input = Console.ReadLine(); string[] truckDetails = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double truckFuel = double.Parse(truckDetails[1]); double truckConsumption = double.Parse(truckDetails[2]); double truckTankCapacity = double.Parse(truckDetails[3]); Vehicle truck = new Truck(truckFuel, truckConsumption, truckTankCapacity); vehicles.Add(truck); input = Console.ReadLine(); string[] busDetails = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double busFuel = double.Parse(busDetails[1]); double busConsumption = double.Parse(busDetails[2]); double busTankCapacity = double.Parse(busDetails[3]); Bus bus = new Bus(busFuel, busConsumption, busTankCapacity); //vehicles.Add(bus); int lines = int.Parse(Console.ReadLine()); for (int i = 0; i < lines; i++) { input = Console.ReadLine(); string[] splittedInput = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string command = splittedInput[0]; string vehicle = splittedInput[1]; double number = double.Parse(splittedInput[2]); if (command == "Drive") { if (vehicle == "Car") { car.Drive(number); } else if (vehicle == "Truck") { truck.Drive(number); } else { bus.Drive(number); } } else if (command == "Refuel") { if (vehicle == "Car") { car.Refuel(number); } else if (vehicle == "Truck") { truck.Refuel(number); } else { bus.Refuel(number); } } else { bus.DriveEmpty(number); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }