Advertisement
Vladkoheca

FlyingTaxi.java

Feb 28th, 2025
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | Source Code | 0 0
  1. public class FlyingTaxi {
  2.     public String model;
  3.     public int maxAltitude;
  4.     public double fuelLevel;
  5.  
  6.     public FlyingTaxi(String model, int maxAltitude, double fuelLevel) {
  7.         this.model = model;
  8.         this.maxAltitude = maxAltitude;
  9.         this.fuelLevel = fuelLevel;
  10.     }
  11.  
  12.     public void displayInfo() {
  13.         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);
  14.     }
  15.  
  16.     public void refuel(double fuelAmount) {
  17.         fuelLevel += fuelAmount;
  18.         System.out.println("The fuel level after the refuel is: " + fuelLevel);
  19.     }
  20.  
  21.     public void flyToDestination(String destination, double distance) {
  22.         double expense = distance * 2;
  23.         if (fuelLevel >= expense) {
  24.             System.out.println("The fuel needed to reach " + destination + " is: " + expense + "\nTherefore you have enough fuel to reach " + destination);
  25.         } else {
  26.             System.out.println("The fuel needed to be refueled to reach " + destination + " is: " + (expense - fuelLevel));
  27.             refuel(expense - fuelLevel);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement