static void Main(string[] args) { string[] carInput = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string[] truckInput = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string[] busInput = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); Car car = new Car(double.Parse(carInput[1]), double.Parse(carInput[2]), double.Parse(carInput[3])); Truck truck = new Truck(double.Parse(truckInput[1]), double.Parse(truckInput[2]), double.Parse(truckInput[3])); Bus bus = new Bus(double.Parse(busInput[1]), double.Parse(busInput[2]), double.Parse(busInput[3])); 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 type = input[1]; double amount = double.Parse(input[2]); if (command == "Drive") { if (type == "Car") { Drive(car, amount); } else if (type == "Truck") { Drive(truck, amount); } else if (type == "Bus") { bus.isEmpty = false; Drive(bus, amount); } } else if (command == "Refuel") { try { if (type == "Car") { car.Refuel(amount); } else if (type == "Truck") { truck.Refuel(amount); } else if (type == "Bus") { bus.Refuel(amount); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } else if (command == "DriveEmpty") { bus.isEmpty = true; Drive(bus, amount); } } Console.WriteLine($"Car: {car.Quantity:f2}"); Console.WriteLine($"Truck: {truck.Quantity:f2}"); Console.WriteLine($"Bus: {bus.Quantity:f2}"); }
static void Main() { var carInput = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); var car = new Car(double.Parse(carInput[1]), double.Parse(carInput[2]), double.Parse(carInput[3])); var truckInput = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); var truck = new Truck(double.Parse(truckInput[1]), double.Parse(truckInput[2]), double.Parse(truckInput[3])); var busInput = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); var bus = new Bus(double.Parse(busInput[1]), double.Parse(busInput[2]), double.Parse(busInput[3])); var n = int.Parse(Console.ReadLine()); for (var i = 0; i < n; i++) { var commandLine = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); var command = commandLine[0]; var vehicle = commandLine[1]; var parameter = double.Parse(commandLine[2]); try { switch (command) { case "Drive": switch (vehicle) { case "Car": Console.WriteLine(car.Drive(parameter)); break; case "Truck": Console.WriteLine(truck.Drive(parameter)); break; case "Bus": Console.WriteLine(bus.Drive(parameter)); break; } break; case "DriveEmpty": bus.SwitchConditionerOff(); Console.WriteLine(bus.Drive(parameter)); bus.SwitchConditionerOn(); break; case "Refuel": switch (vehicle) { case "Car": car.Refuel(parameter); break; case "Truck": truck.Refuel(parameter); break; case "Bus": bus.Refuel(parameter); break; } break; } } catch (ArgumentException e) { Console.WriteLine(e.Message); } } Console.WriteLine(car.Report()); Console.WriteLine(truck.Report()); Console.WriteLine(bus.Report()); }
public void Run() { string[] carInfo = Console.ReadLine().Split(); string[] truckInfo = Console.ReadLine().Split(); string[] busInfo = Console.ReadLine().Split(); double carFuelConsumption = double.Parse(carInfo[2]); double carFuelQuantity = double.Parse(carInfo[1]); int carTankCapacity = int.Parse(carInfo[3]); double truckFuelConsumption = double.Parse(truckInfo[2]); double truckFuelQuantity = double.Parse(truckInfo[1]); int truckTankCapacity = int.Parse(truckInfo[3]); double busFuelConsumption = double.Parse(busInfo[2]); double busFuelQuantity = double.Parse(busInfo[1]); int busTankCapacity = int.Parse(busInfo[3]); Vehicle car = new Car(carFuelQuantity, carFuelConsumption, carTankCapacity); Vehicle truck = new Truck(truckFuelQuantity, truckFuelConsumption, truckTankCapacity); Bus bus = new Bus(busFuelQuantity, busFuelConsumption, busTankCapacity); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(); string command = input[0]; string vehicle = input[1]; try { if (command == "Drive") { if (vehicle == "Car") { car.Drive(double.Parse(input[2])); } else if (vehicle == "Truck") { truck.Drive(double.Parse(input[2])); } else if (vehicle == "Bus") { bus.DriveWithPeople(double.Parse(input[2])); } } else if (command == "Refuel") { if (vehicle == "Car") { car.Refuel(double.Parse(input[2])); } else if (vehicle == "Truck") { truck.Refuel(double.Parse(input[2])); } else if (vehicle == "Bus") { bus.Refuel(double.Parse(input[2])); } } else if (command == "DriveEmpty") { bus.Drive(double.Parse(input[2])); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
static void Main(string[] args) { string[] carI = Console.ReadLine().Split(); Car car = new Car(double.Parse(carI[1]), double.Parse(carI[2]), double.Parse(carI[3])); string[] truckI = Console.ReadLine().Split(); Truck truck = new Truck(double.Parse(truckI[1]), double.Parse(truckI[2]), double.Parse(carI[3])); string[] busI = Console.ReadLine().Split(); Bus bus = new Bus(double.Parse(busI[1]), double.Parse(busI[2]), double.Parse(busI[3])); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] command = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); string action = command[0]; string vehicle = command[1]; double kmOrLt = double.Parse(command[2]); switch (action) { case "Drive": if (vehicle == "Car") { car.Drive(kmOrLt); } else if (vehicle == "Truck") { truck.Drive(kmOrLt); } else if (vehicle == "Bus") { bus.Drive(kmOrLt); } break; case "DriveEmpty": if (vehicle == "Bus") { bus.DriveEmpty(kmOrLt); } break; case "Refuel": if (vehicle == "Car") { car.Refuel(kmOrLt); } else if (vehicle == "Truck") { truck.Refuel(kmOrLt); } else if (vehicle == "Bus") { bus.Refuel(kmOrLt); } break; default: break; } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:f2}"); }
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) { //List<Vehicle> vehicles = new List<Vehicle>(); var carInput = Console.ReadLine().Split(" "); Vehicle car = new Car(double.Parse(carInput[1]), double.Parse(carInput[2]), double.Parse(carInput[3])); //vehicles.Add(car); var truckInput = Console.ReadLine().Split(" "); Vehicle truck = new Truck(double.Parse(truckInput[1]), double.Parse(truckInput[2]), double.Parse(truckInput[3])); //vehicles.Add(truck); var busInput = Console.ReadLine().Split(" "); Bus bus = new Bus(double.Parse(busInput[1]), double.Parse(busInput[2]), double.Parse(busInput[3])); int lines = int.Parse(Console.ReadLine()); for (int i = 0; i < lines; i++) { var command = Console.ReadLine().Split(" "); if (command[0] == "Drive" && command[1] == "Car") { car.Drive(double.Parse(command[2])); } if (command[0] == "Drive" && command[1] == "Truck") { truck.Drive(double.Parse(command[2])); } if (command[0] == "Drive" && command[1] == "Bus") { bus.DriveWithPeople(double.Parse(command[2])); } if (command[0] == "DriveEmpty" && command[1] == "Bus") { bus.Drive(double.Parse(command[2])); } if (command[0] == "Refuel" && command[1] == "Car") { car.Refuel(double.Parse(command[2])); } if (command[0] == "Refuel" && command[1] == "Truck") { truck.Refuel(double.Parse(command[2])); } if (command[0] == "Refuel" && command[1] == "Bus") { bus.Refuel(double.Parse(command[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[] carData = Console.ReadLine() .Split(); //Car 15 0.3 Car car = new Car(double.Parse(carData[1]), double.Parse(carData[2]), double.Parse(carData[3])); string[] truckData = Console.ReadLine() .Split(); Truck truck = new Truck(double.Parse(truckData[1]), double.Parse(truckData[2]), double.Parse(truckData[3])); string[] busData = Console.ReadLine() .Split(); Bus bus = new Bus(double.Parse(busData[1]), double.Parse(busData[2]), double.Parse(busData[3])); 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 (command == "Refuel") { if (type == nameof(Truck)) { truck.Refuel(amount); } else if (type == nameof(Car)) { car.Refuel(amount); } else if (type == nameof(Bus)) { bus.Refuel(amount); } } else if (command == "Drive") { if (type == nameof(Truck)) { Console.WriteLine(truck.Drive(amount)); } else if (type == nameof(Car)) { Console.WriteLine(car.Drive(amount)); } else if (type == nameof(Bus)) { Console.WriteLine(bus.Drive(amount)); } } else if (command == "DriveEmpty") { Console.WriteLine(bus.DriveEmpty(amount)); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
static void Main() { string[] carInfo = Console.ReadLine().Split(); string[] truckInfo = Console.ReadLine().Split(); string[] busInfo = Console.ReadLine().Split(); int count = int.Parse(Console.ReadLine()); double carFuel = double.Parse(carInfo[1]); double carConsumption = double.Parse(carInfo[2]); double carTank = double.Parse(carInfo[3]); double truckFuel = double.Parse(truckInfo[1]); double truckConsumption = double.Parse(truckInfo[2]); double truckTank = double.Parse(truckInfo[3]); double busFuel = double.Parse(busInfo[1]); double busConsumption = double.Parse(busInfo[2]); double busTank = double.Parse(busInfo[3]); Car car = new Car(carFuel, carConsumption, carTank); Truck truck = new Truck(truckFuel, truckConsumption, truckTank); Bus bus = new Bus(busFuel, busConsumption, busTank); for (int i = 0; i < count; i++) { string[] commandLine = Console.ReadLine().Split(); string command = commandLine[0]; string type = commandLine[1]; switch (type) { case "Car": if (command == "Drive") { double distance = double.Parse(commandLine[2]); Console.WriteLine(car.Drive(distance)); } else if (command == "Refuel") { double fuel = double.Parse(commandLine[2]); car.Refuel(fuel); } break; case "Truck": if (command == "Drive") { double distance = double.Parse(commandLine[2]); Console.WriteLine(truck.Drive(distance)); } else if (command == "Refuel") { double fuel = double.Parse(commandLine[2]); truck.Refuel(fuel); } break; case "Bus": if (command == "Drive") { double distance = double.Parse(commandLine[2]); Console.WriteLine(bus.Drive(distance)); } else if (command == "Refuel") { double fuel = double.Parse(commandLine[2]); bus.Refuel(fuel); } else if (command == "DriveEmpty") { double distance = double.Parse(commandLine[2]); Console.WriteLine(bus.DriveEmpty(distance)); } break; } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
static void Main(string[] args) { Car car = null; Truck truck = null; Bus bus = null; for (int i = 0; i < 3; i++) { string[] vehicleArgs = Console.ReadLine().Split(); if (vehicleArgs[0] == "Car") { car = new Car(double.Parse(vehicleArgs[1]), double.Parse(vehicleArgs[2]), double.Parse(vehicleArgs[3])); } else if (vehicleArgs[0] == "Truck") { truck = new Truck(double.Parse(vehicleArgs[1]), double.Parse(vehicleArgs[2]), double.Parse(vehicleArgs[3])); } else if (vehicleArgs[0] == "Bus") { bus = new Bus(double.Parse(vehicleArgs[1]), double.Parse(vehicleArgs[2]), double.Parse(vehicleArgs[3])); } } int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] command = Console.ReadLine().Split(); if (command[0] == "Drive") { if (command[1] == "Car") { double distance = double.Parse(command[2]); Console.WriteLine(car.Drive(distance)); } else if (command[1] == "Truck") { double distance = double.Parse(command[2]); Console.WriteLine(truck.Drive(distance)); } else if (command[1] == "Bus") { double distance = double.Parse(command[2]); Console.WriteLine(bus.Drive(distance)); } } else if (command[0] == "Refuel") { try { if (command[1] == "Car") { double amount = double.Parse(command[2]); car.Refuel(amount); } else if (command[1] == "Truck") { double amount = double.Parse(command[2]); truck.Refuel(amount); } else if (command[1] == "Bus") { double amount = double.Parse(command[2]); bus.Refuel(amount); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } else if (command[0] == "DriveEmpty") { if (command[1] == "Bus") { double distance = double.Parse(command[2]); Console.WriteLine(bus.Drive(distance)); } } } 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()); }
static void Main(string[] args) { string[] carData = Console.ReadLine().Split(); string[] truckData = Console.ReadLine().Split(); string[] busData = Console.ReadLine().Split(); Vehicle car = new Car(double.Parse(carData[1]), double.Parse(carData[2]), double.Parse(carData[3])); Vehicle truck = new Truck(double.Parse(truckData[1]), double.Parse(truckData[2]), double.Parse(truckData[3])); Bus bus = new Bus(double.Parse(busData[1]), double.Parse(busData[2]), double.Parse(busData[3])); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] command = Console.ReadLine().Split(); double arg = double.Parse(command[2]); try { if (command[0] == "Drive") { if (command[1] == "Car") { car.Drive(arg); } else if (command[1] == "Truck") { truck.Drive(arg); } else if (command[1] == "Bus") { bus.IsEmpty = false; bus.Drive(arg); } } else if (command[0] == "Refuel") { if (command[1] == "Car") { car.Refuel(arg); } else if (command[1] == "Truck") { truck.Refuel(arg); } else if (command[1] == "Bus") { bus.Refuel(arg); } } else { bus.IsEmpty = true; bus.Drive(arg); } } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:F2}"); }
public void Run() { string[] carInfo = Console.ReadLine() .Split() .ToArray(); string[] truckInfo = Console.ReadLine() .Split() .ToArray(); string[] busInfo = Console.ReadLine() .Split() .ToArray(); double carFuelQuantity = double.Parse(carInfo[1]); double carFuelConsumption = double.Parse(carInfo[2]); double carTankCapacity = double.Parse(carInfo[3]); double truckFuelQuantity = double.Parse(truckInfo[1]); double truckConsumption = double.Parse(truckInfo[2]); double truckTankCapacity = double.Parse(truckInfo[3]); double busFuelQuantity = double.Parse(busInfo[1]); double busFuelConsumption = double.Parse(busInfo[2]); double busTankCapacity = double.Parse(busInfo[3]); var car = new Car(carFuelQuantity, carFuelConsumption, carTankCapacity); var truck = new Truck(truckFuelQuantity, truckConsumption, truckTankCapacity); var bus = new Bus(busFuelQuantity, busFuelConsumption, busTankCapacity); int count = int.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { try { 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 (vehicleType == "Bus") { bus.IsEmpty = false; DriveVehicle(bus, value); } } else if (command == "Refuel") { if (vehicleType == "Car") { car.Refuel(value); } else if (vehicleType == "Truck") { truck.Refuel(value); } else if (vehicleType == "Bus") { bus.Refuel(value); } } else if (command == "DriveEmpty") { bus.IsEmpty = true; DriveVehicle(bus, value); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine($"Car: {Math.Round(car.FuelQuantity, 2, MidpointRounding.ToEven):F2}"); Console.WriteLine($"Truck: {Math.Round(truck.FuelQuantity, 2, MidpointRounding.ToEven):F2}"); Console.WriteLine($"Bus: {Math.Round(bus.FuelQuantity, 2, MidpointRounding.ToEven):F2}"); }
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()); }
static void Main(string[] args) { string[] carInfo = Console.ReadLine() .Split() .ToArray(); string[] truckInfo = Console.ReadLine() .Split() .ToArray(); string[] busInfo = Console.ReadLine() .Split() .ToArray(); double carFuelQuantity = double.Parse(carInfo[1]); double carFuelConsumption = double.Parse(carInfo[2]); double carTankCapacity = double.Parse(carInfo[3]); double truckFuelQuantity = double.Parse(truckInfo[1]); double truckFuelConsumption = double.Parse(truckInfo[2]); double truckTankCapacity = double.Parse(truckInfo[3]); double busFuelQuantity = double.Parse(busInfo[1]); double busFuelConsumption = double.Parse(busInfo[2]); double busTankCapacity = double.Parse(busInfo[3]); Car car = new Car(carFuelQuantity, carFuelConsumption, carTankCapacity); Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption, truckTankCapacity); Bus bus = new Bus(busFuelQuantity, busFuelConsumption, busTankCapacity); int countLines = int.Parse(Console.ReadLine()); for (int i = 0; i < countLines; i++) { try { string[] line = Console.ReadLine() .Split() .ToArray(); string command = line[0]; string vehicleType = line[1]; double value = double.Parse(line[2]); if (command == "Drive") { if (vehicleType == "Car") { DriveVehicle(car, value); } else if (vehicleType == "Truck") { DriveVehicle(truck, value); } else if (vehicleType == "Bus") { bus.isEmpty = false; DriveVehicle(bus, value); } } else if (command == "Refuel") { if (vehicleType == "Car") { car.Refuel(value); } else if (vehicleType == "Truck") { truck.Refuel(value); } else if (vehicleType == "Bus") { bus.Refuel(value); } } else if (command == "DriveEmpty") { bus.isEmpty = true; DriveVehicle(bus, value); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:F2}"); }
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()); }
public static void Main() { // First Exercise // var carInfo = Console.ReadLine().Split(' '); // Vehicle car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2])); // // var truckInfo = Console.ReadLine().Split(' '); // Vehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2])); // // var commandsNumber = int.Parse(Console.ReadLine()); // for (int i = 0; i < commandsNumber; i++) // { // var commandTokens = Console.ReadLine().Split(' '); // var vehicleType = commandTokens[1]; // if (vehicleType == "Car") // { // ExecuteAction(car, commandTokens[0], double.Parse(commandTokens[2])); // } // else // { // ExecuteAction(truck, commandTokens[0], double.Parse(commandTokens[2])); // } // } // // Console.WriteLine(car); // Console.WriteLine(truck); var carInfo = Console.ReadLine().Split(' '); Vehicle car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2]), double.Parse(carInfo[3])); var truckInfo = Console.ReadLine().Split(' '); Vehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2]), double.Parse(truckInfo[3])); var busInfo = Console.ReadLine().Split(' '); Vehicle bus = new Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3])); var commandsNumber = int.Parse(Console.ReadLine()); for (int i = 0; i < commandsNumber; i++) { try { var commandTokens = Console.ReadLine().Split(' '); var vehicleType = commandTokens[1]; if (vehicleType == "Car") { ExecuteAction(car, commandTokens[0], double.Parse(commandTokens[2])); } else if (vehicleType == "Truck") { ExecuteAction(truck, commandTokens[0], double.Parse(commandTokens[2])); } else if (vehicleType == "Bus") { ExecuteAction(bus, commandTokens[0], double.Parse(commandTokens[2])); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
static void Main(string[] args) { var inputCar = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToList(); double carFuelQuantity = double.Parse(inputCar[1]); double carLitersPerKm = double.Parse(inputCar[2]); double carTrunkCapacity = double.Parse(inputCar[3]); Vehicle car = new Car(carFuelQuantity, carLitersPerKm, carTrunkCapacity); var inputTruck = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToList(); double truckFuelQuantity = double.Parse(inputTruck[1]); double truckLitersPerKm = double.Parse(inputTruck[2]); double truckTrunkCapacity = double.Parse(inputTruck[3]); Vehicle truck = new Truck(truckFuelQuantity, truckLitersPerKm, truckTrunkCapacity); var inputBus = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToList(); double busFuelQuantity = double.Parse(inputBus[1]); double busLitersPerKm = double.Parse(inputBus[2]); double busTrunkCapacity = double.Parse(inputBus[3]); Vehicle bus = new Bus(busFuelQuantity, busLitersPerKm, busTrunkCapacity); int num = int.Parse(Console.ReadLine()); for (int i = 0; i < num; i++) { var commands = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToList(); string command = commands[0]; string vehicle = commands[1]; double distance = double.Parse(commands[2]); if (command == "Drive") { if (vehicle == "Car") { car.Drive(distance); } else if (vehicle == "Truck") { truck.Drive(distance); } else { ((Bus)bus).TurnOnAirconditioner(); bus.Drive(distance); } } else if (command == "DriveEmpty") { ((Bus)bus).TurnOffAirconditioner(); bus.Drive(distance); } else if (command == "Refuel") { double fuel = double.Parse(commands[2]); if (vehicle == "Car") { car.Refuel(fuel); } else if (vehicle == "Truck") { truck.Refuel(fuel); } else { bus.Refuel(fuel); } } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {(truck.FuelQuantity):F2}"); Console.WriteLine($"Bus: {(bus.FuelQuantity):F2}"); }
static void Main(string[] args) { Car car = null; Truck truck = null; Bus bus = null; for (int i = 0; i < 3; i++) { string[] vehicleInfo = Console.ReadLine().Split(); if (vehicleInfo[0] == "Car") { double vehicleFuelQuantity = double.Parse(vehicleInfo[1]); double vehicleFuelConsumption = double.Parse(vehicleInfo[2]); double tankCapacity = double.Parse(vehicleInfo[3]); car = new Car(vehicleFuelQuantity, vehicleFuelConsumption, tankCapacity); } else if (vehicleInfo[0] == "Bus") { double vehicleFuelQuantity = double.Parse(vehicleInfo[1]); double vehicleFuelConsumption = double.Parse(vehicleInfo[2]); double tankCapacity = double.Parse(vehicleInfo[3]); bus = new Bus(vehicleFuelQuantity, vehicleFuelConsumption, tankCapacity); } else { double vehicleFuelQuantity = double.Parse(vehicleInfo[1]); double vehicleFuelConsumption = double.Parse(vehicleInfo[2]); double tankCapacity = double.Parse(vehicleInfo[3]); truck = new Truck(vehicleFuelQuantity, vehicleFuelConsumption, tankCapacity); } } int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] cmdArgs = Console.ReadLine().Split(); string action = cmdArgs[0]; string vehicle = cmdArgs[1]; if (action == "Drive" && vehicle == "Car") { double distance = double.Parse(cmdArgs[2]); car.Drive(distance); } else if (action == "Drive" && vehicle == "Truck") { double distance = double.Parse(cmdArgs[2]); truck.Drive(distance); } else if (action == "Refuel" && vehicle == "Car") { double liters = double.Parse(cmdArgs[2]); car.Refuel(liters); } else if (action == "Refuel" && vehicle == "Truck") { double liters = double.Parse(cmdArgs[2]); truck.Refuel(liters); } else if (action == "Drive" && vehicle == "Bus") { double distance = double.Parse(cmdArgs[2]); bus.Drive(distance); } else if (action == "DriveEmpty" && vehicle == "Bus") { double distance = double.Parse(cmdArgs[2]); bus.DriveEmpty(distance); } else if (action == "Refuel" && vehicle == "Bus") { double liters = double.Parse(cmdArgs[2]); bus.Refuel(liters); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
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[] carInfo = Console.ReadLine().Split(); string[] truckInfo = Console.ReadLine().Split(); string[] busInfo = Console.ReadLine().Split(); int n = int.Parse(Console.ReadLine()); double carFuel = double.Parse(carInfo[1]); double carFuelConsumption = double.Parse(carInfo[2]); double carTankCapacity = double.Parse(carInfo[3]); Vehicle car = new Car(carFuel, carFuelConsumption, carTankCapacity); double truckFuel = double.Parse(truckInfo[1]); double truckFuelConsumption = double.Parse(truckInfo[2]); double truckTankCapacity = double.Parse(truckInfo[3]); Vehicle truck = new Truck(truckFuel, truckFuelConsumption, truckTankCapacity); double busFuel = double.Parse(busInfo[1]); double busFuelConsumption = double.Parse(busInfo[2]); double busTankCapacity = double.Parse(busInfo[3]); Bus bus = new Bus(busFuel, busFuelConsumption, busTankCapacity); for (int i = 0; i < n; i++) { string[] cmdParts = Console.ReadLine().Split(); string command = cmdParts[0]; string typeVehicle = cmdParts[1]; double distance = double.Parse(cmdParts[2]); double fuel = distance; if (command == "Drive") { if (typeVehicle == "Car") { car.Drive(distance); } else if (typeVehicle == "Truck") { truck.Drive(distance); } else { bus.Drive(distance); } } else if (command == "Refuel") { try { if (typeVehicle == "Car") { car.Refuel(fuel); } else if (typeVehicle == "Truck") { truck.Refuel(fuel); } else { bus.Refuel(fuel); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } else if (command == "DriveEmpty" && typeVehicle == "Bus") { bus.DriveEmpty(fuel); } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:F2}"); } // 75/100? }
static void Main(string[] args) { // Soulution can not contains any compilation errors or warnings! // STAGE 1: 3.0 points Console.WriteLine("\nSTAGE 1"); Console.WriteLine("\nBasic test"); Car car1 = new Car("Car1"); car1.Travel(13.5); Bus bus1 = new Bus("Bus1"); uint passengers1 = 100; if (bus1.SetPassengerCount(passengers1)) { Console.WriteLine($"[Error] Bus can not carry more then {Bus.passengerLimit} passengers."); } else { Console.WriteLine($"[OK] Bus can not carry more then {Bus.passengerLimit} passengers."); } uint passengers2 = 23; if (bus1.SetPassengerCount(passengers2)) { Console.WriteLine($"[OK] Bus can carry {bus1.PassengerCount()} passengers."); } else { Console.WriteLine($"[Error] Bus should be able to carry {passengers2} passengers."); } bus1.Travel(120.4); Truck truck1 = new Truck("Truck1"); double load1 = 2682.3; if (truck1.SetLoad(load1)) { Console.WriteLine($"[Error] Truck can not transport more then {Truck.capacity} kg."); } else { Console.WriteLine($"[OK] Truck can not transport more then {Truck.capacity} kg."); } double load2 = 1682.3; if (truck1.SetLoad(load2)) { Console.WriteLine($"[OK] Truck can transport {truck1.Load()} kg."); } else { Console.WriteLine($"[Error] Truck should be able to transport {load2} kg."); } truck1.Travel(203.8); Vehicle[] fleet = { car1, new Car("Car2"), bus1, truck1 }; Console.WriteLine("\nFleet:"); for (int i = 0; i < fleet.Length; i++) { Console.WriteLine(fleet[i]); } bus1.SetPassengerCount(32); Console.WriteLine("\nFleet travel:"); for (int i = 0; i < fleet.Length; i++) { fleet[i].Travel(342.4); } // STAGE 2: 1.0 points Console.WriteLine("\nSTAGE 2"); //Console.WriteLine("\nBeeps: "); //car1.Beep(); //bus1.Beep(); //truck1.Beep(); //Console.WriteLine("\nVehicle beeps: "); //Vehicle vehicle = car1; //vehicle.Beep(); //vehicle = bus1; //vehicle.Beep(); //vehicle = truck1; //vehicle.Beep(); // STAGE 3: 1.0 points Console.WriteLine("\nSTAGE 3"); //Console.WriteLine("\nNew fleet order:"); //string[,] orders = { // { "car", "New car 1" }, // { "truck", "New truck 1" }, // { "bus", "New bus 1" }, // { "motorcycle", "This should not be created" }, // { "bus", "New bus 2" } //}; //// Implement order creation here //for ( ... ) //{ //... //} }
static void Main(string[] args) { // var carinput = Console.ReadLine().Split(' '); // var fuelAmount = double.Parse(carinput[1]); // var fuelConsumption = double.Parse(carinput[2]); // var tankCapacity = ParseTankCapacity(fuelAmount,double.Parse(carinput[3])); // IVehicle car = new Car(fuelAmount, fuelConsumption, tankCapacity); // // var truckInput = Console.ReadLine().Split(' '); // fuelAmount = double.Parse(truckInput[1]); // fuelConsumption = double.Parse(truckInput[2]); // tankCapacity = ParseTankCapacity(fuelAmount,double.Parse(truckInput[3])); // IVehicle truck = new Truck(fuelAmount, fuelConsumption,tankCapacity); // // var busInput = Console.ReadLine().Split(' '); // fuelAmount = double.Parse(busInput[1]); // fuelConsumption = double.Parse(busInput[2]); // tankCapacity = ParseTankCapacity(fuelAmount, double.Parse(busInput[3])); // Bus bus = new Bus(fuelAmount, fuelConsumption, tankCapacity); List<IVehicle> vehicles = new List<IVehicle>(); for(int i = 0; i < 3; i++) { var inputTokens = Console.ReadLine().Split(); var vehicleType = inputTokens[0]; var passedFuel = double.Parse(inputTokens[1]); var vehicleConsumption = double.Parse(inputTokens[2]); var vehicleTankCapacity = double.Parse(inputTokens[3]); var vehicleFuel = ParseFuel(passedFuel, vehicleTankCapacity); IVehicle vehicle=null; switch (vehicleType) { case "Car": vehicle = new Car(vehicleFuel, vehicleConsumption, vehicleTankCapacity); break; case "Truck": vehicle = new Truck(vehicleFuel, vehicleConsumption, vehicleTankCapacity); break; case "Bus": vehicle = new Bus(vehicleFuel, vehicleConsumption, vehicleTankCapacity); break; } vehicles.Add(vehicle); } var totalInputs = int.Parse(Console.ReadLine()); Car car = (Car)vehicles.Find(v => v.GetType().Name == "Car"); Truck truck = (Truck)vehicles.Find(v => v.GetType().Name == "Truck"); Bus bus = (Bus)vehicles.Find(v => v.GetType().Name == "Bus"); for (int i = 0; i< totalInputs; i++) { var inputLine = Console.ReadLine(); var inputTokens = inputLine.Split(' '); var command = inputTokens[0]; var vehicle = inputTokens[1]; var distanceOrAmount = double.Parse(inputTokens[2]); if(command == "Refuel" && distanceOrAmount <= 0) { Console.WriteLine("Fuel must be a positive number"); continue; } switch (command) { case "Drive": if(vehicle == "Car") { car.Drive(distanceOrAmount); } else if(vehicle == "Truck") { truck.Drive(distanceOrAmount); } else if(vehicle == "Bus") { bus.Drive(distanceOrAmount); } break; case "Refuel": if(vehicle == "Car") { car.Refuel(distanceOrAmount); } else if(vehicle == "Truck") { truck.Refuel(distanceOrAmount); } else if(vehicle == "Bus") { bus.Refuel(distanceOrAmount); } break; case "DriveEmpty": bus.DriveEmpty(distanceOrAmount); break; } } foreach(var vehicle in vehicles) { Console.WriteLine(vehicle); } }
private static void ExecuteCommands(Car car, Truck truck, Bus bus) { var numberOfCommands = int.Parse(Console.ReadLine()); while (numberOfCommands > 0) { numberOfCommands--; var command = Console.ReadLine().Split(); var action = command[0]; var vehicleType = command[1]; var value = double.Parse(command[2]); try { switch (action) { case "Drive": Console.WriteLine(vehicleType == "Car" ? car.Drive(value) : vehicleType == "Truck" ? truck.Drive(value) : bus.Drive(value)); break; case "Refuel": switch (vehicleType) { case "Car": car.Refuel(value); break; case "Truck": truck.Refuel(value); break; case "Bus": bus.Refuel(value); break; default: break; } break; case "DriveEmpty": bus.IsAirConditionerTurnedOn = false; Console.WriteLine(bus.Drive(value)); bus.IsAirConditionerTurnedOn = true; break; default: break; } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } }
static void Main(string[] args) { string[] inputCar = Console.ReadLine().Split(new[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries); double fuelCar = double.Parse(inputCar[1]); double litresCar = double.Parse(inputCar[2]); double tankCar = double.Parse(inputCar[3]); var car = new Car(fuelCar, litresCar, tankCar); string[] inputTruck = Console.ReadLine().Split(new[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries); double fuelTruck = double.Parse(inputTruck[1]); double litresTruck = double.Parse(inputTruck[2]); double tankTruck = double.Parse(inputTruck[3]); var truck = new Truck(fuelTruck, litresTruck, tankTruck); string[] inputBus = Console.ReadLine().Split(new[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries); double fuelBus = double.Parse(inputBus[1]); double litresBus = double.Parse(inputBus[2]); double tankBus = double.Parse(inputBus[3]); var bus = new Bus(fuelBus, litresBus, tankBus); int number = int.Parse(Console.ReadLine()); for (int i = 0; i < number; i++) { string[] input = Console.ReadLine().Split(new[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries); string command = input[0]; string machine = input[1]; double distance = double.Parse(input[2]); if (command == "Drive") { if (machine == "Car") { car.Drive(distance); } else if (machine == "Truck") { truck.Drive(distance); } else { bus.Drive(distance); } } else if (command == "Refuel") { if (machine == "Car") { car.Refuel(distance); } else if (machine == "Truck") { truck.Refuel(distance); } else { bus.Refuel(distance); } } else { bus.ConditionOf(); bus.Drive(distance); } } Console.WriteLine($"Car: {car.Fuel:F2}"); Console.WriteLine($"Truck: {truck.Fuel:F2}"); Console.WriteLine($"Bus: {bus.Fuel:F2}"); }
public void Run() { List <string> vehicleInfo = Console.ReadLine().Split().ToList(); double carFuelQuantity = double.Parse(vehicleInfo[1]); double carFuelConsumtion = double.Parse(vehicleInfo[2]); double carTankCapacity = double.Parse(vehicleInfo[3]); Car car = new Car(carFuelQuantity, carFuelConsumtion, carTankCapacity); vehicleInfo = Console.ReadLine().Split().ToList(); double truckFuelQuantity = double.Parse(vehicleInfo[1]); double truckFuelConsumtion = double.Parse(vehicleInfo[2]); double truckTankCapacity = double.Parse(vehicleInfo[3]); Truck truck = new Truck(truckFuelQuantity, truckFuelConsumtion, truckTankCapacity); vehicleInfo = Console.ReadLine().Split().ToList(); double busFuelQuantity = double.Parse(vehicleInfo[1]); double busFuelConsumtion = double.Parse(vehicleInfo[2]); double busTankCapacity = double.Parse(vehicleInfo[3]); Bus bus = new Bus(busFuelQuantity, busFuelConsumtion, busTankCapacity); int numberCommands = int.Parse(Console.ReadLine()); for (int j = 0; j < numberCommands; j++) { try { List <string> inputInfo = Console.ReadLine().Split().ToList(); string command = inputInfo[0]; string type = inputInfo[1]; double value = double.Parse(inputInfo[2]); if (type == "Car") { ExecuteCommand(command, value, car); } else if (type == "Truck") { ExecuteCommand(command, value, truck); } else if (type == "Bus") { ExecuteCommand(command, value, bus); } } catch (Exception exp) { Console.WriteLine(exp.Message); continue; } } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:F2}"); }
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()); }
static void Main(string[] args) { string[] carArgs = Console.ReadLine().Split(); double carFuel = double.Parse(carArgs[1]); double carLitersPerKilometer = double.Parse(carArgs[2]); double carCapacity = double.Parse(carArgs[3]); Car car = new Car(carFuel, carLitersPerKilometer, carCapacity); string[] truckArgs = Console.ReadLine().Split(); double truckFuel = double.Parse(truckArgs[1]); double truckLitersPerKilometer = double.Parse(truckArgs[2]); double truckCapacity = double.Parse(truckArgs[3]); Truck truck = new Truck(truckFuel, truckLitersPerKilometer, truckCapacity); string[] busArgs = Console.ReadLine().Split(); double busFuel = double.Parse(busArgs[1]); double busLiters = double.Parse(busArgs[2]); double busCapacity = double.Parse(busArgs[3]); Bus bus = new Bus(busFuel, busLiters, busCapacity); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] inputArgs = Console.ReadLine().Split(); string command = inputArgs[0]; string vehicleType = inputArgs[1]; double measures = double.Parse(inputArgs[2]); try { if (command == "Drive") { if (vehicleType == "Car") { Console.WriteLine(car.Drive(measures)); } else if (vehicleType == "Truck") { Console.WriteLine(truck.Drive(measures)); } else if (vehicleType == "Bus") { Console.WriteLine(bus.Drive(measures)); } } else if (command == "Refuel") { if (vehicleType == "Car") { car.Refuel(measures); } else if (vehicleType == "Truck") { truck.Refuel(measures); } else if (vehicleType == "Bus") { bus.Refuel(measures); } } else if (command == "DriveEmpty") { Console.WriteLine(bus.DriveEmpty(measures)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
public static void Main(string[] args) { var carInfo = Console.ReadLine().Split(); var truckInfo = Console.ReadLine().Split(); var busInfo = Console.ReadLine().Split(); 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 Bus(double.Parse(busInfo[1]), double.Parse(busInfo[2]), double.Parse(busInfo[3])); var commands = int.Parse(Console.ReadLine()); for (int i = 0; i < commands; i++) { var tokens = Console.ReadLine().Split(); var command = tokens[0]; var vehicle = tokens[1]; if (command.StartsWith("Drive")) { double distance = double.Parse(tokens[2]); switch (vehicle) { case "Car": Console.WriteLine(car.Drive(distance)); break; case "Truck": Console.WriteLine(truck.Drive(distance)); break; case "Bus": var someBus = bus as Bus; Console.WriteLine(command == "Drive" ? someBus.Drive(distance) : someBus.DriveEmpty(distance)); break; } } else if (command == "Refuel") { try { double fuel = double.Parse(tokens[2]); switch (vehicle) { case "Car": car.Refuel(fuel); break; case "Truck": truck.Refuel(fuel); break; case "Bus": bus.Refuel(fuel); break; } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } } Console.WriteLine($"{nameof(Car)}: {car.FuelQuantity:f2}"); Console.WriteLine($"{nameof(Truck)}: {truck.FuelQuantity:f2}"); Console.WriteLine($"{nameof(Bus)}: {bus.FuelQuantity:f2}"); }
static void Main(string[] args) { string[] carArg = Console.ReadLine().Split(); Car car = new Car(double.Parse(carArg[1]), double.Parse(carArg[2]), double.Parse(carArg[3])); string[] truckArg = Console.ReadLine().Split(); Truck truck = new Truck(double.Parse(truckArg[1]), double.Parse(truckArg[2]), double.Parse(truckArg[3])); string[] busArg = Console.ReadLine().Split(); Bus bus = new Bus(double.Parse(busArg[1]), double.Parse(busArg[2]), double.Parse(busArg[3])); int numberOfCommand = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommand; i++) { string[] commandArg = Console.ReadLine().Split(); double methodArg = double.Parse(commandArg[2]); if (commandArg[0] == "Drive") { if (commandArg[1] == "Car") { Console.WriteLine(car.Drive(methodArg)); } else if (commandArg[1] == "Truck") { Console.WriteLine(truck.Drive(methodArg)); } else if (commandArg[1] == "Bus") { Console.WriteLine(bus.Drive(methodArg)); } } else if (commandArg[0] == "Refuel") { try { if (commandArg[1] == "Car") { car.Refuel(methodArg); } else if (commandArg[1] == "Truck") { truck.Refuel(methodArg); } else if (commandArg[1] == "Bus") { bus.Refuel(methodArg); } } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } } else if (commandArg[0] == "DriveEmpty" && commandArg[1] == "Bus") { bus.TurOffAirConditioner(); Console.WriteLine(bus.Drive(methodArg)); bus.TurnOnAirConditioner(); } } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
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()); }