static void Main(string[] args) { var carInfo = Console.ReadLine().Split(); var truckInfo = Console.ReadLine().Split(); var busInfo = Console.ReadLine().Split(); var carFuelQuantity = double.Parse(carInfo[1]); var carConsumption = double.Parse(carInfo[2]); var carTankCapacity = double.Parse(carInfo[3]); var truckFuelQuantity = double.Parse(truckInfo[1]); var truckConsumption = double.Parse(truckInfo[2]); var truckTankCapacity = double.Parse(truckInfo[3]); var busFuelQuantity = double.Parse(busInfo[1]); var busConsumption = double.Parse(busInfo[2]); var busTankCapacity = double.Parse(busInfo[3]); IVehicle car = new Car(carFuelQuantity, carConsumption, carTankCapacity); IVehicle truck = new Truck(truckFuelQuantity, truckConsumption, truckTankCapacity); IVehicle bus = new Bus(busFuelQuantity, busConsumption, busTankCapacity); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var input = Console.ReadLine().Split(); var value = double.Parse(input[2]); switch (input[1]) { case "Car": Action(car, input[0], value); break; case "Truck": Action(truck, input[0], value); break; case "Bus": Action(bus, input[0], value); break; } } Print(car.ToString()); Print(truck.ToString()); Print(bus.ToString()); }
static void Main(string[] args) { var carInfo = Console.ReadLine().Split(); var fuelQuantity = double.Parse(carInfo[1]); var fuelConsumption = double.Parse(carInfo[2]); var tankCapacity = double.Parse(carInfo[3]); var car = new Car(tankCapacity, fuelQuantity, fuelConsumption); var truckInfo = Console.ReadLine().Split(); fuelQuantity = double.Parse(truckInfo[1]); fuelConsumption = double.Parse(truckInfo[2]); tankCapacity = double.Parse(truckInfo[3]); var truck = new Truck(tankCapacity, fuelQuantity, fuelConsumption); var busInfo = Console.ReadLine().Split(); fuelQuantity = double.Parse(busInfo[1]); fuelConsumption = double.Parse(busInfo[2]); tankCapacity = double.Parse(busInfo[3]); var bus = new Bus(tankCapacity, fuelQuantity, fuelConsumption); var count = int.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { var commandData = Console.ReadLine().Split(); var command = commandData[0]; var vehicleType = commandData[1]; if (command == "Drive") { var distance = double.Parse(commandData[2]); if (vehicleType == "Car") { Console.WriteLine(car.Drive(0.9, distance, vehicleType)); } else if (vehicleType == "Truck") { Console.WriteLine(truck.Drive(1.6, distance, vehicleType)); } else { Console.WriteLine(bus.Drive(1.4, distance, vehicleType)); } } else if (command == "DriveEmpty") { var distance = double.Parse(commandData[2]); Console.WriteLine(bus.Drive(0.0, distance, vehicleType)); } else { try { var fuelToAdd = double.Parse(commandData[2]); if (vehicleType == "Car") { try { car.Refuel(fuelToAdd); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else if (vehicleType == "Truck") { try { truck.Refuel(fuelToAdd); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { try { bus.Refuel(fuelToAdd); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); Console.WriteLine(bus.ToString()); }
static void Main(string[] args) { var carDetails = Console.ReadLine().Split(); var truckDetails = Console.ReadLine().Split(); var busDetails = Console.ReadLine().Split(); var car = new Car(double.Parse(carDetails[1]), double.Parse(carDetails[2]), double.Parse(carDetails[3])); var truck = new Truck(double.Parse(truckDetails[1]), double.Parse(truckDetails[2]), double.Parse(truckDetails[3])); var bus = new Bus(double.Parse(busDetails[1]), double.Parse(busDetails[2]), double.Parse(busDetails[3])); var commands = int.Parse(Console.ReadLine()); for (int i = 0; i < commands; i++) { var command = Console.ReadLine().Split(); var vehicleType = command[1]; try { if (command[0] == "Drive") { var distance = double.Parse(command[2]); 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[0] == "Refuel") { var fuel = double.Parse(command[2]); if (vehicleType == "Car") { car.Refuel(fuel); } else if (vehicleType == "Truck") { truck.Refuel(fuel); } else if (vehicleType == "Bus") { bus.Refuel(fuel); } } else if (command[0] == "DriveEmpty") { var distance = double.Parse(command[2]); Console.WriteLine(bus.DriveEmpty(distance)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); Console.WriteLine(bus.ToString()); }
static void Main(string[] args) { var carData = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); double fuelQuantity = double.Parse(carData[1]); double fuelConsumption = double.Parse(carData[2]); double tankCapacity = double.Parse(carData[3]); Car car = new Car(fuelQuantity, fuelConsumption, tankCapacity); var truckData = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); fuelQuantity = double.Parse(truckData[1]); fuelConsumption = double.Parse(truckData[2]); tankCapacity = double.Parse(truckData[3]); Truck truck = new Truck(fuelQuantity, fuelConsumption, tankCapacity); var busData = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); fuelQuantity = double.Parse(busData[1]); fuelConsumption = double.Parse(busData[2]); tankCapacity = double.Parse(busData[3]); Bus bus = new Bus(fuelQuantity, fuelConsumption, tankCapacity); int num = int.Parse(Console.ReadLine()); for (int i = 0; i < num; i++) { var cmd = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); string command = cmd[0]; if (command == "Drive") { string type = cmd[1]; double km = double.Parse(cmd[2]); if (type == "Car") { car.Drive(km); } else if (type == "Truck") { truck.Drive(km); } else if (type == "Bus") { bus.Drive(km); } } else if (command == "DriveEmpty") { string type = cmd[1]; double km = double.Parse(cmd[2]); if (type == "Bus") { bus.DriveEmpty(km); } } else if (command == "Refuel") { string type = cmd[1]; double litters = double.Parse(cmd[2]); if (type == "Car") { car.Refuel(litters); } else if (type == "Truck") { truck.Refuel(litters); } else if (type == "Bus") { bus.Refuel(litters); } } } //Console.WriteLine($"Car: {car.FuelQuantity:F2}"); //Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); //Console.WriteLine($""); Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); Console.WriteLine(bus.ToString()); }
static void Main(string[] args) { string[] carInput = ReadInfoFromConsole(); string[] truckInput = ReadInfoFromConsole(); string[] busInput = ReadInfoFromConsole(); Car car = (Car)CreateVehicle(carInput); Truck truck = (Truck)CreateVehicle(truckInput); Bus bus = (Bus)CreateVehicle(busInput); int numberOfCommands = int.Parse(Console.ReadLine()); while (numberOfCommands > 0) { try { string[] commands = ReadInfoFromConsole(); string typeOfVehicle = commands[1]; string action = commands[0]; double number = double.Parse(commands[2]); switch (typeOfVehicle) { case "Car": if (action == "Drive") { car.Drive(number); } else if (action == "Refuel") { car.Refuel(number); } break; case "Truck": if (action == "Drive") { truck.Drive(number); } else if (action == "Refuel") { truck.Refuel(number); } break; case "Bus": if (action == "DriveEmpty") { bus.TypeOfBus = "empty"; bus.Drive(number); } else if (action == "Drive") { bus.Drive(number); } else if (action == "Refuel") { bus.Refuel(number); } break; default: break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } numberOfCommands--; } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); Console.WriteLine(bus.ToString()); }
static void Main(string[] args) { string[] carArgs = Console.ReadLine().Split(); string[] truckArgs = Console.ReadLine().Split(); string[] busArgs = Console.ReadLine().Split(); Car car = new Car(double.Parse(carArgs[1]), double.Parse(carArgs[2]), double.Parse(carArgs[3])); Truck truck = new Truck(double.Parse(truckArgs[1]), double.Parse(truckArgs[2]), double.Parse(truckArgs[3])); Bus bus = new Bus(double.Parse(busArgs[1]), double.Parse(busArgs[2]), double.Parse(busArgs[3])); int count = int.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { string[] input = Console.ReadLine().Split(); string thingToDo = input[0]; string vehicleType = input[1]; double distanceOrFuelQuant = double.Parse(input[2]); if (thingToDo == "Drive") { switch (vehicleType) { case "Car": car.DriveVehicle(distanceOrFuelQuant); break; case "Truck": truck.DriveVehicle(distanceOrFuelQuant); break; case "Bus": bus.IsFull = true; bus.DriveVehicle(distanceOrFuelQuant); break; } } if (thingToDo == "DriveEmpty") { bus.IsFull = false; bus.DriveVehicle(distanceOrFuelQuant); } if (thingToDo == "Refuel") { switch (vehicleType) { case "Car": car.RefuelVehicle(distanceOrFuelQuant); break; case "Truck": truck.RefuelVehicle(distanceOrFuelQuant); break; case "Bus": bus.RefuelVehicle(distanceOrFuelQuant); break; } } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); Console.WriteLine(bus.ToString()); }
public static void Main(string[] args) { var input = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); Car car = new Car(double.Parse(input[1]), double.Parse(input[2]), double.Parse(input[3])); input = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); Truck truck = new Truck(double.Parse(input[1]), double.Parse(input[2]), double.Parse(input[3])); input = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); Bus bus = new Bus(double.Parse(input[1]), double.Parse(input[2]), double.Parse(input[3])); var commands = int.Parse(Console.ReadLine()); for (int i = 0; i < commands; i++) { var tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); try { if (tokens[0] == "Drive") { var distance = double.Parse(tokens[2]); if (tokens[1] == "Car") { Console.WriteLine(car.Drive(distance)); } else if (tokens[1] == "Truck") { Console.WriteLine(truck.Drive(distance)); } else { Console.WriteLine(bus.Drive(distance)); } } else if (tokens[0] == "Refuel") { var fuelAmount = double.Parse(tokens[2]); if (tokens[1] == "Car") { car.Refuel(fuelAmount); } else if (tokens[1] == "Truck") { truck.Refuel(fuelAmount); } else { bus.Refuel(fuelAmount); } } else { var distance = double.Parse(tokens[2]); Console.WriteLine(bus.DriveEmpty(distance)); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message.ToString()); } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); Console.WriteLine(bus.ToString()); }
public void Run() { Car car = CreateCar(); Truck truck = CreateTruck(); Bus bus = CreateBus(); 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]; if (command == "Drive") { double distance = double.Parse(commandArgs[2]); if (vechicleType == "Car") { Console.WriteLine(car.Drive(distance)); } else if (vechicleType == "Truck") { Console.WriteLine(truck.Drive(distance)); } else if (vechicleType == "Bus") { Console.WriteLine(bus.Drive(distance)); } } else if (command == "DriveEmpty") { double distance = double.Parse(commandArgs[2]); Console.WriteLine(bus.DriveEmpty(distance)); } else if (command == "Refuel") { double fuelAmount = double.Parse(commandArgs[2]); if (vechicleType == "Car") { car.Refuel(fuelAmount); } else if (vechicleType == "Truck") { truck.Refuel(fuelAmount); } else if (vechicleType == "Bus") { bus.Refuel(fuelAmount); } } } catch (ArgumentException ae) { Console.WriteLine(ae.Message); continue; } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); Console.WriteLine(bus.ToString()); }
private static void Main() { string[] carItems = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double carFuelQuantity = double.Parse(carItems[1]); double carFuelConsumption = double.Parse(carItems[2]); double carTankCapacity = double.Parse(carItems[3]); Car car = new Car(carFuelQuantity, carFuelConsumption, carTankCapacity); string[] truckItems = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double truckFuelQuantity = double.Parse(truckItems[1]); double truckFuelConsumption = double.Parse(truckItems[2]); double truckTankCapacity = double.Parse(truckItems[3]); Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption, truckTankCapacity); string[] busItems = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double busFuelQuantity = double.Parse(busItems[1]); double busFuelConsumption = double.Parse(busItems[2]); double busTankCapacity = double.Parse(busItems[3]); Bus bus = new Bus(busFuelQuantity, busFuelConsumption, busTankCapacity); int count = int.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { try { 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 if (type == "Truck") { Console.WriteLine(truck.Drive(distance)); } else if (type == "Bus") { Console.WriteLine(bus.Drive(distance)); } } else if (command == "Refuel") { double fuel = double.Parse(commandItems[2]); if (type == "Car") { car.Refuel(fuel); } else if (type == "Truck") { truck.Refuel(fuel); } else if (type == "Bus") { bus.Refuel(fuel); } } else if (command == "DriveEmpty") { double distance = double.Parse(commandItems[2]); Console.WriteLine(bus.DriveEmpty(distance)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); Console.WriteLine(bus.ToString()); }