Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FlyingTaxi {
- public String model;
- public int maxAltitude;
- public double fuelLevel;
- public FlyingTaxi(String model, int maxAltitude, double fuelLevel) {
- this.model = model;
- this.maxAltitude = maxAltitude;
- this.fuelLevel = fuelLevel;
- }
- public void displayInfo() {
- System.out.println("The model of the flying taxi is: " + model + "\nThe max altitude of the flying taxi is: " + maxAltitude + "\nThe current fuel level of the flying taxi is: " + fuelLevel);
- }
- public void refuel(double fuelAmount) {
- fuelLevel += fuelAmount;
- System.out.println("The fuel level after the refuel is: " + fuelLevel);
- }
- public void flyToDestination(String destination, double distance) {
- double expense = distance * 2;
- if (fuelLevel >= expense) {
- System.out.println("The fuel needed to reach " + destination + " is: " + expense + "\nTherefore you have enough fuel to reach " + destination);
- } else {
- System.out.println("The fuel needed to be refueled to reach " + destination + " is: " + (expense - fuelLevel));
- refuel(expense - fuelLevel);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement