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}"); }
static void Main() { Console.WriteLine("ML Start вебинар C# 2 задание 2 \n\n"); #region Демо легковушки Car c1 = new Car("А343АЗ43", 90); c1.Refuel(new FuelAI95()); c1.ChangeCurrentSpeed(50); c1.Move(8); c1.ChangeCurrentSpeed(100); c1.Move(1); c1.Refuel(new FuelAI92()); c1.Move(1); Console.WriteLine($"Итого тачанка {c1.RegNumber} намотала {c1.Kilometrage} км\n\n"); #endregion #region Демо автобуса Bus b1 = new Bus("Е001КХ777", 60); b1.Refuel(new FuelAI92()); b1.AddPassengers(2); b1.ChangeCurrentSpeed(40); b1.Move(2); b1.Refuel(new FuelDiesel()); b1.Move(2); b1.ChangeCurrentSpeed(0); b1.AddPassengers(21); b1.ChangeCurrentSpeed(30); b1.Move(1); Console.WriteLine($"Итого автобус {b1.RegNumber} проехал {b1.Kilometrage} км\n\n"); #endregion #region Демо грузовика Truck t1 = new Truck("В747ОР35", 70); t1.Refuel(new FuelAI95()); t1.ChangeCurrentSpeed(1200); t1.Move(1); t1.AddCargo(4); t1.ChangeCurrentSpeed(70); t1.Move(2); t1.AddCargo(-5); t1.AddCargo(-3); t1.Refuel(new FuelDiesel()); t1.Move(10); Console.WriteLine($"Итого грузовик {t1.RegNumber} намотал {t1.Kilometrage} км"); #endregion Console.ReadKey(); }
public void Command(int number) { for (int i = 0; i < number; i++) { string[] input = Console.ReadLine().Split().ToArray(); string action = input[0]; string type = input[1]; double distance = double.Parse(input[2]); action = action.ToLower(); type = type.ToLower(); if (action == "drive") { if (type == "car") { car.Drive(distance); } else if (type == "truck") { truck.Drive(distance); } } else if (action == "refuel") { double liters = distance; if (type == "car") { car.Refuel(liters); } else if (type == "truck") { truck.Refuel(liters); } } } }
private static void DriveAndRefuel(Car car, Truck truck) { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] commandParams = Console.ReadLine().Split(' '); if (commandParams[0] == "Drive") { if (commandParams[1] == "Car") { car.Drive(double.Parse(commandParams[2])); } if (commandParams[1] == "Truck") { truck.Drive(double.Parse(commandParams[2])); } } else if (commandParams[0] == "Refuel") { if (commandParams[1] == "Car") { car.Refuel(double.Parse(commandParams[2])); } if (commandParams[1] == "Truck") { truck.Refuel(double.Parse(commandParams[2])); } } } }
public void Run() { var carArray = Console.ReadLine().Split().ToList(); var truckArray = Console.ReadLine().Split().ToList(); var busArray = Console.ReadLine().Split().ToList(); Car car = new Car(double.Parse(carArray[1]), double.Parse(carArray[2]), double.Parse(carArray[3])); Truck truck = new Truck(double.Parse(truckArray[1]), double.Parse(truckArray[2]), double.Parse(truckArray[3])); Bus bus = new Bus(double.Parse(busArray[1]), double.Parse(busArray[2]), double.Parse(busArray[3])); int count = int.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { var arg = Console.ReadLine().Split(); string command = arg[0]; string type = arg[1]; double km = double.Parse(arg[2]); if (command == "Drive") { if (type == "Truck") { Console.WriteLine(truck.Drive(km)); } else if (type == "Car") { Console.WriteLine(car.Drive(km)); } else if (type == "Bus") { Console.WriteLine(bus.Drive(km)); } } else if (command == "Refuel") { if (type == "Car") { car.Refuel(km); } else if (type == "Truck") { truck.Refuel(km); } else if (type == "Bus") { bus.Refuel(km); } } else if (command == "DriveEmpty") { Console.WriteLine(bus.DriveEmpty(km)); } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); Console.WriteLine($"Bus: {bus.FuelQuantity:f2}"); }
static void Main() { Car car = (Car)Factory(); Truck truck = (Truck)Factory(); Bus bus = (Bus)Factory(); int cnt = int.Parse(Console.ReadLine()); while (cnt > 0) { string command = Console.ReadLine(); string[] data = command.Split(); string action = data[0] + data[1]; double argument = double.Parse(data[2]); try { switch (action) { case "DriveCar": Console.WriteLine(car.Drive(argument)); break; case "DriveTruck": Console.WriteLine(truck.Drive(argument)); break; case "DriveBus": Console.WriteLine(bus.Drive(argument)); break; case "DriveEmptyBus": Console.WriteLine(bus.DriveEmpty(argument)); break; case "RefuelCar": car.Refuel(argument); break; case "RefuelTruck": truck.Refuel(argument); break; case "RefuelBus": bus.Refuel(argument); break; } } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } cnt--; } Console.WriteLine(car); Console.WriteLine(truck); Console.WriteLine(bus); }
public static void Main() { 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 n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] args = Console.ReadLine().Split(); try { ParseCommands(args); } catch (Exception e) { Console.WriteLine(e.Message); } } void ParseCommands(string[] args) { string command = args[0]; string typeOfVehicle = args[1]; double fuelOrDistance = double.Parse(args[2]); if (typeOfVehicle == "Car") { if (command == "Drive") { car.Drive(fuelOrDistance); } else { car.Refuel(fuelOrDistance); } } else if (typeOfVehicle == "Truck") { if (command == "Drive") { truck.Drive(fuelOrDistance); } else { truck.Refuel(fuelOrDistance); } } } Console.WriteLine(car); Console.WriteLine(truck); }
public void Run() { string[] carInfo = Console.ReadLine().Split(); string[] truckInfo = Console.ReadLine().Split(); 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 n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { try { string[] inputArgs = Console.ReadLine().Split(); string action = inputArgs[0]; string vehicleType = inputArgs[1]; double value = double.Parse(inputArgs[2]); if (action == "Refuel") { if (vehicleType == "Car") { car.Refuel(value); } else { truck.Refuel(value); } } else { if (vehicleType == "Car") { car.Drive(value); } else { truck.Drive(value); } } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } Console.WriteLine(car); Console.WriteLine(truck); }
public static void Main() { var carParams = Console.ReadLine().Split().Skip(1).Select(double.Parse).ToArray(); var car = new Car(carParams[0], carParams[1], carParams[2]); var truckParams = Console.ReadLine().Split(' ').Skip(1).Select(double.Parse).ToArray(); var truck = new Truck(truckParams[0], truckParams[1], truckParams[2]); var busParams = Console.ReadLine().Split(' ').Skip(1).Select(double.Parse).ToArray(); var bus = new Bus(busParams[0], busParams[1], busParams[2]); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var commandArgs = Console.ReadLine().Split(); var command = commandArgs[0]; var vehicle = commandArgs[1]; var amount = double.Parse(commandArgs[2]); try { if (command == "Drive") { switch (vehicle) { case "Car": Console.WriteLine(car.Drive(amount)); break; case "Truck": Console.WriteLine(truck.Drive(amount)); break; case "Bus": Console.WriteLine(bus.Drive(amount)); break; } } else if (command == "Refuel") { switch (vehicle) { case "Car": car.Refuel(amount); break; case "Truck": truck.Refuel(amount); break; case "Bus": bus.Refuel(amount); break; } } else { Console.WriteLine(bus.DriveEmpty(amount)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); Console.WriteLine(bus.ToString()); }
static void Main(string[] args) { string[] carInfo = Console.ReadLine().Split().Skip(1).ToArray(); double fuelQuantityCar = double.Parse(carInfo[0]); double litersPerKmCar = double.Parse(carInfo[1]); Vihicle car = new Car(fuelQuantityCar, litersPerKmCar); string[] truckInfo = Console.ReadLine().Split().Skip(1).ToArray(); double fuelQuantityTruck = double.Parse(truckInfo[0]); double litersPerKmTruck = double.Parse(truckInfo[1]); Vihicle truck = new Truck(fuelQuantityTruck, litersPerKmTruck); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(); string command = input[0]; string vihicle = input[1]; double distance = double.Parse(input[2]); double liters = distance; switch (command) { case "Drive": switch (vihicle) { case "Car": car.Drive(distance); break; case "Truck": truck.Drive(distance); break; } break; case "Refuel": switch (vihicle) { case "Car": car.Refuel(liters); break; case "Truck": truck.Refuel(liters); break; } break; } } Console.WriteLine($"Car: {Math.Round(car.FuelQuntity, 2):F2}"); Console.WriteLine($"Truck: {Math.Round(truck.FuelQuntity, 2):F2}"); }
static void Main(string[] args) { var vehicles = new List <Vehicles>(); var carTokens = Console.ReadLine().Split(); var truckTokens = Console.ReadLine().Split(); var car = new Car(double.Parse(carTokens[1]), double.Parse(carTokens[2])); var truck = new Truck(double.Parse(truckTokens[1]), double.Parse(truckTokens[2])); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var token = Console.ReadLine().Split(); var cmd = token[0]; var type = token[1]; if (type == "Car") { switch (cmd) { case "Drive": car.Drive(double.Parse(token[2])); break; case "Refuel": car.Refuel(double.Parse(token[2])); break; default: break; } } else { switch (cmd) { case "Drive": truck.Drive(double.Parse(token[2])); break; case "Refuel": truck.Refuel(double.Parse(token[2])); break; default: break; } } } vehicles.Add(car); vehicles.Add(truck); foreach (var item in vehicles) { Console.WriteLine(item.ToString()); } }
static void Main() { var carInfo = Console.ReadLine().Split(); var carFuel = double.Parse(carInfo[1]); var carFuelConsumption = double.Parse(carInfo[2]); Car car = new Car(carFuel, carFuelConsumption); var truckInfo = Console.ReadLine().Split(); var truckFuel = double.Parse(truckInfo[1]); var truckFuelConsumption = double.Parse(truckInfo[2]); Truck truck = new Truck(truckFuel, truckFuelConsumption); var numberOfCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommands; i++) { var line = Console.ReadLine().Split(); switch (line[0]) { case "Drive": double distance = double.Parse(line[2]); switch (line[1]) { case "Car": var result = car.Drive(distance); Console.WriteLine(result); break; case "Truck": result = truck.Drive(distance); Console.WriteLine(result); break; } break; case "Refuel": double liters = double.Parse(line[2]); switch (line[1]) { case "Car": car.Refuel(liters); break; case "Truck": truck.Refuel(liters); break; } break; } } Console.WriteLine(car); Console.WriteLine(truck); }
static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); string[] carArgs = Console.ReadLine() .Split(); double carFuelQantity = double.Parse(carArgs[1]); double carFuelConsumption = double.Parse(carArgs[2]); Car car = new Car(carFuelQantity, carFuelConsumption); string[] truckArgs = Console.ReadLine() .Split(); double truckFuelQuantity = double.Parse(truckArgs[1]); double truckFuelConsumption = double.Parse(truckArgs[2]); Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption); int commandsCount = int.Parse(Console.ReadLine()); for (int i = 0; i < commandsCount; i++) { string[] commandArgs = Console.ReadLine() .Split(); string command = commandArgs[0]; string commandType = commandArgs[1]; if (command == "Drive") { double distance = double.Parse(commandArgs[2]); if (commandType == "Car") { Console.WriteLine(car.Drive(distance)); } else { Console.WriteLine(truck.Drive(distance)); } } else { double fuelAmount = double.Parse(commandArgs[2]); if (commandType == "Car") { car.Refuel(fuelAmount); } else { truck.Refuel(fuelAmount); } } } Console.WriteLine(car); Console.WriteLine(truck); }
public static void Main() { var carInfo = Console.ReadLine().Split(new[] { ' ' } , StringSplitOptions.RemoveEmptyEntries) .ToList(); var fuelQuantity = double.Parse(carInfo[1]); var litersPerKm = double.Parse(carInfo[2]); var currentCar = new Car(fuelQuantity, litersPerKm); // var truckInfo = Console.ReadLine().Split(new[] { ' ' } , StringSplitOptions.RemoveEmptyEntries) .ToList(); var fuelQuantityTruck = double.Parse(truckInfo[1]); var litersPerKmTruck = double.Parse(truckInfo[2]); var currentTruck = new Truck(fuelQuantityTruck, litersPerKmTruck); var n = int.Parse(Console.ReadLine()); for (var i = 0; i < n; i++) { var commands = Console.ReadLine().Split(new[] { ' ' } , StringSplitOptions.RemoveEmptyEntries) .ToList(); var command = commands[0]; var vehicleType = commands[1]; switch (command) { case "Drive": var distance = double.Parse(commands[2]); if (vehicleType == "Car") { currentCar.Drive(distance); } else { currentTruck.Drive(distance); } break; case "Refuel": var liters = double.Parse(commands[2]); if (vehicleType == "Car") { currentCar.Refuel(liters); } else { currentTruck.Refuel(liters); } break; } } Console.WriteLine(currentCar); Console.WriteLine(currentTruck); }
public static void Main() { string[] carInformation = Console.ReadLine().Split(); double carFuelQuantity = double.Parse(carInformation[1]); double carLitersPerKm = double.Parse(carInformation[2]); Vehicle car = new Car(carFuelQuantity, carLitersPerKm); string [] truckInformation = Console.ReadLine().Split(); double truckFuelQuantity = double.Parse(truckInformation[1]); double truckLitersPerKm = double.Parse(truckInformation[2]); Vehicle truck = new Truck(truckFuelQuantity, truckLitersPerKm); int numberOfCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommands; i++) { string[] commands = Console.ReadLine().Split(); string command = commands[0]; string vehicle = commands[1]; double value = double.Parse(commands[2]); switch (vehicle) { case nameof(Car): switch (command) { case "Drive": Console.WriteLine(car.Drive(value)); break; case "Refuel": car.Refuel(value); break; } break; case nameof(Truck): switch (command) { case "Drive": Console.WriteLine(truck.Drive(value)); break; case "Refuel": truck.Refuel(value); break; } break; } } Console.WriteLine(car); Console.WriteLine(truck); }
static void Main(string[] args) { var carInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); Car car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2])); var truckInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); Truck truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2])); var numberOfLines = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfLines; i++) { var command = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); try { switch (command[0]) { case "Drive": if (command[1] == "Car") { car.Drive(double.Parse(command[2])); } else if (command[1] == "Truck") { truck.Drive(double.Parse(command[2])); } break; case "Refuel": if (command[1] == "Car") { car.Refuel(double.Parse(command[2])); } else if (command[1] == "Truck") { truck.Refuel(double.Parse(command[2])); } break; default: break; } } catch (Exception e) { Console.WriteLine(e.Message); continue; } } Console.WriteLine($"Car: {car.FuelAmount:f2}"); Console.WriteLine($"Truck: {truck.FuelAmount:f2}"); }
static void Main() { string[] carInfo = Console.ReadLine().Split().ToArray(); double carFuelQuantity = double.Parse(carInfo[1]); double carFuelConsumption = double.Parse(carInfo[2]); string[] truckInfo = Console.ReadLine().Split().ToArray(); double truckFuelQuantity = double.Parse(truckInfo[1]); double truckFuelConsumption = double.Parse(truckInfo[2]); var car = new Car(carFuelQuantity, carFuelConsumption); var truck = new Truck(truckFuelQuantity, truckFuelConsumption); int numberOfCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommands; i++) { string[] commandInfo = Console.ReadLine().Split().ToArray(); string command = commandInfo[0]; string vehicleType = commandInfo[1]; if (command.Equals("Drive")) { double km = double.Parse(commandInfo[2]); if (vehicleType.Equals("Car")) { car.Drive(km); } else if (vehicleType.Equals("Truck")) { truck.Drive(km); } } else if (command.Equals("Refuel")) { double liters = double.Parse(commandInfo[2]); if (vehicleType.Equals("Car")) { car.Refuel(liters); } else if (vehicleType.Equals("Truck")) { truck.Refuel(liters); } } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); }
static void Main() { string[] carTokens = ReadInput(); string[] truckTokens = ReadInput(); double carFuelQuantity = double.Parse(carTokens[1]); double carLitersPerKm = double.Parse(carTokens[2]); double truckFuelQuantity = double.Parse(truckTokens[1]); double truckLitersPerKm = double.Parse(truckTokens[2]); Vehicle car = new Car(carFuelQuantity, carLitersPerKm); Vehicle truck = new Truck(truckFuelQuantity, truckLitersPerKm); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] commandTokens = ReadInput(); switch (commandTokens[0]) { case "Drive": double distance = double.Parse(commandTokens[2]); if (commandTokens[1] == "Car") { car.Drive(distance); } else if (commandTokens[1] == "Truck") { truck.Drive(distance); } break; case "Refuel": double liters = double.Parse(commandTokens[2]); if (commandTokens[1] == "Car") { car.Refuel(liters); } else if (commandTokens[1] == "Truck") { truck.Refuel(liters); } break; } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); }
private static void CommandParser(Car car, Truck truck, Bus bus) { var commandParams = Console.ReadLine()?.Split(); string vechicle = commandParams[1]; string command = commandParams[0]; double number = double.Parse(commandParams[2]); if (vechicle == "Car") { switch (command) { case "Drive": Console.WriteLine(car.Drive(number)); break; case "Refuel": car.Refuel(number); break; } } else if (vechicle == "Truck") { switch (command) { case "Drive": Console.WriteLine(truck.Drive(number)); break; case "Refuel": truck.Refuel(number); break; } } else if (vechicle == "Bus") { switch (command) { case "Drive": Console.WriteLine(bus.Drive(number)); break; case "DriveEmpty": Console.WriteLine(bus.DriveEmpty(number)); break; case "Refuel": bus.Refuel(number); break; } } }
public static void Main(string[] args) { var inputCarInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var inputTruckInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Vehicles car = new Car(double.Parse(inputCarInfo[1]), double.Parse(inputCarInfo[2]), IncreaseFuelForACCar); Vehicles truck = new Truck(double.Parse(inputTruckInfo[1]), double.Parse(inputTruckInfo[2]), IncreaseFuelForACTruck); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var commandInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var command = commandInfo[0]; var typeVehicle = commandInfo[1]; var distanceOrLiters = double.Parse(commandInfo[2]); try { if (typeVehicle == "Car") { if (command == "Drive") { Console.WriteLine(car.Drive(distanceOrLiters)); } else { car.Refuel(distanceOrLiters); } } else { if (command == "Drive") { Console.WriteLine(truck.Drive(distanceOrLiters)); } else { truck.Refuel(distanceOrLiters); } } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); }
public void Run() { string[] carInfo = Console.ReadLine().Split(); string[] truckInfo = Console.ReadLine().Split(); double carFuelQuantity = double.Parse(carInfo[1]); double carFuelConsumption = double.Parse(carInfo[2]); double truckFuelQuantity = double.Parse(truckInfo[1]); double truckFuelConsumption = double.Parse(truckInfo[2]); IVehicle car = new Car(carFuelQuantity, carFuelConsumption); IVehicle truck = new Truck(truckFuelQuantity, truckFuelConsumption); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] args = Console.ReadLine().Split(); string action = args[0]; string type = args[1]; double value = double.Parse(args[2]); if (action == "Refuel") { if (type == "Car") { car.Refuel(value); } else { truck.Refuel(value); } } else { if (type == "Car") { car.Drive(value); } else { truck.Drive(value); } } } Console.WriteLine(car); Console.WriteLine(truck); }
public void Run() { string[] carInput = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); double fuelCar = double.Parse(carInput[1]); double carConsumption = double.Parse(carInput[2]); Car car = new Car(fuelCar, carConsumption); string[] truckInput = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); double fuelTruck = double.Parse(truckInput[1]); double truckConsumption = double.Parse(truckInput[2]); Truck truck = new Truck(fuelTruck, truckConsumption); int numberLines = int.Parse(Console.ReadLine()); for (int i = 0; i < numberLines; i++) { string[] commands = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); string action = commands[0]; string typeVehicle = commands[1]; if (action == "Drive") { double distance = double.Parse(commands[2]); if (typeVehicle == "Car") { car.Drive(distance); } else if (typeVehicle == "Truck") { truck.Drive(distance); } } else if (action == "Refuel") { double fuelQuantity = double.Parse(commands[2]); if (typeVehicle == "Car") { car.Refuel(fuelQuantity); } else if (typeVehicle == "Truck") { truck.Refuel(fuelQuantity); } } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity: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; } }
private void Refuel(double liters, string vehicleType) { if (vehicleType == "Car") { _car.Refuel(liters); } else if (vehicleType == "Truck") { _truck.Refuel(liters); } else if (vehicleType == "Bus") { _bus.Refuel(liters); } }
static void Main(string[] args) { string[] carInfo = Console.ReadLine().Split(); string[] truckInfo = Console.ReadLine().Split(); double carFuelQuantity = double.Parse(carInfo[1]); double carFuelConsumption = double.Parse(carInfo[2]); double truckFuelQuantity = double.Parse(truckInfo[1]); double truckFuelConsumption = double.Parse(truckInfo[2]); Car car = new Car(carFuelQuantity, carFuelConsumption); Truck truck = new Truck(truckFuelQuantity, truckFuelConsumption); int numberOfCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommands; i++) { string[] command = Console.ReadLine().Split(); string commandType = command[0]; string vehicleType = command[1]; double ammount = double.Parse(command[2]); if (commandType.ToLower() == "drive") { if (vehicleType.ToLower() == "car") { car.Drive(ammount); } else { truck.Drive(ammount); } } else if (commandType.ToLower() == "refuel") { if (vehicleType.ToLower() == "car") { car.Refuel(ammount); } else { truck.Refuel(ammount); } } } Console.WriteLine($"Car: {car.FuelQuantity:f2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:f2}"); }
public static void Main() { var carInfo = Console.ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); Vehicle car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2])); var truckInfo = Console.ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); Vehicle truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2])); var countCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < countCommands; i++) { var input = Console.ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); var command = input[0]; var vehicle = input[1]; if (command == "Drive") { var distane = double.Parse(input[2]); if (vehicle == "Car") { car.Drive(distane); } else if (vehicle == "Truck") { truck.Drive(distane); } } else if (command == "Refuel") { var liters = double.Parse(input[2]); if (vehicle == "Car") { car.Refuel(liters); } else if (vehicle == "Truck") { truck.Refuel(liters); } } } Console.WriteLine(car); Console.WriteLine(truck); }
public static void Main(string[] args) { string[] carInfo = Console.ReadLine().Split(); double fuelQuantity = double.Parse(carInfo[1]); double fuelConsumption = double.Parse(carInfo[2]); Car car = new Car(fuelQuantity, fuelConsumption); string[] truckInfo = Console.ReadLine().Split(); double fuelQuantityOfTruck = double.Parse(truckInfo[1]); double fuelConsumptionOfTruck = double.Parse(truckInfo[2]); Truck truck = new Truck(fuelQuantityOfTruck, fuelConsumptionOfTruck); int timesToRead = int.Parse(Console.ReadLine()); for (int i = 0; i < timesToRead; i++) { string input = Console.ReadLine(); string[] tokens = input.Split(); if (input.Contains("Drive Car")) { double distance = double.Parse(tokens[2]); Console.WriteLine(car.Drive(distance)); } else if (input.Contains("Drive Truck")) { double distance = double.Parse(tokens[2]); Console.WriteLine(truck.Drive(distance)); } else if (input.Contains("Refuel Car")) { double fuel = double.Parse(tokens[2]); car.Refuel(fuel); } else if (input.Contains("Refuel Truck")) { double fuel = double.Parse(tokens[2]); truck.Refuel(fuel); } } Console.WriteLine($"Car: {car.FuelQuantity:F2}"); Console.WriteLine($"Truck: {truck.FuelQuantity:F2}"); }
static void Main(string[] args) { string[] carinfo = Console.ReadLine().Split(' ').ToArray(); string[] truckinfo = Console.ReadLine().Split(' ').ToArray(); Car car = new Car(Convert.ToSingle(carinfo[1]), Convert.ToSingle(carinfo[2])); Truck truck = new Truck(Convert.ToSingle(truckinfo[1]), Convert.ToSingle(truckinfo[2])); int N = int.Parse(Console.ReadLine()); string totaltext = Console.ReadLine(); for (int i = 0; i < N - 1; i++) { totaltext = totaltext + ";" + Console.ReadLine(); } Console.WriteLine("---------------------"); for (int i = 0; i < N; i++) { string[] text = totaltext.Split(';').ToArray(); string[] textinfo = text[i].Split(' ').ToArray(); float data = Convert.ToSingle(textinfo[2]); if (textinfo[0] == "Drive") { if (textinfo[1] == "Car") { car.Drive(data, true); } else { truck.Drive(data, true); } } else { if (textinfo[1] == "Car") { car.Refuel(data); } else { truck.Refuel(data); } } } car.Fue(); truck.Fue(); Console.ReadKey(); }
public void Run() { Car car = carFactory.MakeCar(); Truck truck = truckFactory.MakeTruck(); int commandCount = int.Parse(Console.ReadLine()); for (int i = 0; i < commandCount; i++) { string[] commandData = Console.ReadLine().Split(); string commandType = commandData[0]; string vehicleType = commandData[1]; double number = double.Parse(commandData[2]); if (commandType.ToLower() == "drive") { double distance = number; if (vehicleType.ToLower() == "car") { Console.WriteLine(car.Drive(distance)); } else if (vehicleType.ToLower() == "truck") { Console.WriteLine(truck.Drive(distance)); } } else if (commandType.ToLower() == "refuel") { double fuel = number; if (vehicleType.ToLower() == "car") { car.Refuel(fuel); } else if (vehicleType.ToLower() == "truck") { truck.Refuel(fuel); } } } Console.WriteLine(car.ToString()); Console.WriteLine(truck.ToString()); }
private static void PrintRefuelCommand(Car car, Truck truck, Bus bus, string[] commandItems, string type) { 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); } }
public static void Main() { string[] carInfo = Console.ReadLine().Split().ToArray(); string[] truckInfo = Console.ReadLine().Split().ToArray(); Car car = new Car(double.Parse(carInfo[1]), double.Parse(carInfo[2])); Truck truck = new Truck(double.Parse(truckInfo[1]), double.Parse(truckInfo[2])); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] commandArgs = Console.ReadLine().Split().ToArray(); string command = commandArgs[0]; string vehicle = commandArgs[1]; double number = double.Parse(commandArgs[2]); if (command == "Drive") { if (vehicle == "Car") { Console.WriteLine(car.Drive(number)); } else if (vehicle == "Truck") { Console.WriteLine(truck.Drive(number)); } } else if (command == "Refuel") { if (vehicle == "Car") { car.Refuel(number); } else if (vehicle == "Truck") { truck.Refuel(number); } } } Console.WriteLine(car); Console.WriteLine(truck); }