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 doWork() { // TODO: Console.WriteLine("Journey by airplane:"); Airplane myPlane = new Airplane(); myPlane.StartEngine("Contact"); myPlane.TakeOff(); myPlane.Drive(); myPlane.Land(); myPlane.StopEngine("Whirr"); Console.WriteLine("\nJourney by car:"); Car myCar = new Car(); myCar.StartEngine("Brm"); myCar.Accelerate(); myCar.Drive(); myCar.Brake(); myCar.StopEngine("Phut"); Console.WriteLine("\nTesting polymorphism"); Vehicle v = myCar; v.Drive(); v = myPlane; v.Drive(); }
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}"); }