Question: Java!! here is my code, but they're still not past the question. My code: public double getMileage() { return mileage; } public void setMileage(double mileage)
Java!! here is my code, but they're still not past the question.


My code:
public double getMileage() { return mileage; }
public void setMileage(double mileage) { if (mileage > 0) this.mileage = mileage; }
public float getFlightHours() { return flightHours; }
public void setFlightHours(float flightHours) { if (flightHours > 0) this.flightHours = flightHours; }
// TODO: add the 4 overloaded fly methods public void fly(float hours) { mileage = AVG_SPEED * hours; } public void fly(double miles) { mileage += miles; flightHours = (int)(flightHours + (miles/AVG_SPEED)); } public void fly(float hours ,int speed ) { if(speed>MAX_SPEED) speed = MAX_SPEED; if(hoursMAX_SPEED) speed = MAX_SPEED; mileage = miles / speed; } public static void main(String[] args) { Plane plane = new Plane("Delta", "Air-bus 3000", 10000.0, 18.0f); plane.fly(2200.0); //output: Mileage: 12200.0, Hours of flight: 22.0 System.out.println(plane); }
public String toString() { return "Plane [mileage=" + mileage + ", flightHours=" + flightHours + "]"; } }

Plane class (method overload) Complete the code for the class Plane. The variable mileage refers to the accumulated number of miles that a plane has traveled and the variable hoursFlight refers to the accumulated number of hours that a plane has traveled. Here is the definition of the four variants of the method fly (speed of the plane is given in mph), written in UML notation: + fly(hours: float) + fly(miles: double) + fly hours: flight, speed: int) + fly(miles: double, speed: int) Whenever a flight is taken by executing the method fly in any of its four variants, the mileage and the flightHours need to be updated accordingly. When speed is not provided in the method fly, you need to use the constant AVG_SPEED. If the provided speed is greater that the MAX_SPEED, you need to use MAX_SPEED You also need to complete the getters/setters for mileage and flightHours (Note: no negative or zero mileage flightHours or speed are allowed, if that happens, current values of mileage and flightHours must be kept the same) More instructions on how to implement the missing parts of this class are provided in the code below. 2 1 public class Plane { private String airline: 3 private String model: private double mileage: 5 private float flightHours: 4 6 7 550://average speed of the plane final int AVG_SPEED in mph final int MAX_SPEED mph 8 750://max speed of the plane in 9 10 11 12 public Plane () { mileage = 0.0: flightHours = 0.0f: airline = "LATAM" ; model "Boeing 787" : 13 14 model = "Boeing 787" ; 14 15 } 16 17 18 19 public Plane (String airline, String model, double mileage, float flightHours) { this. airline airline: this, model = model: this. mileage mileage: this. flightHours = flightHours: } 20 = 21 22 23 24 25 public void setAirline (String airline) { this. airline = airline; } 26 27 28 29 30 31 32 33 public String getAirline () { return airline : } public void setModel (String model) { this. model = model: } 34 35 36 37 38 39 40 public String getModel() { return model: } // TODO: add the missing getters/setters for mileage and flightHours 41 42 43 // TODO: add the 4 overloaded fly methods 44 45 46 47 48 Feedback Passed Code ran: Plane plane=new Plane(); plane.fly(10.0f); -> Expected output: Mileage: 5500.0, Hours of flight: 10.0 | Actual output: Mileage: 5500.0, Hours of flight: 0.0 Code ran: Plane plane = new Plane("KLM", "Air-bus 3000", 50000.0, 80.0f); plane.fly(0.0f); - > Expected output: Mileage: 50000.0, Hours of flight: 80.0 | Actual output: Mileage: 0.0, Hours of flight: 80.0 Code ran: Plane plane = new Plane(); plane.fly(2700.0, 600); -> Expected output: Mileage: 2700.0, Hours of flight: 4.5| Actual output: Mileage: 4.5, Hours of flight: 0.0 Code ran: Plane plane = Plane("KLM", "Air-bus 3000", 50000.0, 75.0f); plane.fly(-9000,600); -> Expected output: Mileage: 50000.0, Hours of flight: 75.0 | Actual output: Mileage: -15.0, Hours of flight: 75.0 Code ran: Plane plane = Plane("KLM", "Air-bus 7000", 3000.0, 15.5f); plane.fly(10500.0,2000); -> Expected output: Mileage: 13500.0, Hours of flight: 29.5 | Actual output: Mileage: 14.0, Hours of flight: 15.5 Code ran: Plane plane = Plane("Air Canada", "Boeing 800", 4000.0, 20.5f); plane.fly(8000.0,-1000); -> Expected output: Mileage: 4000.0, Hours of flight: 20.5 | Actual output: Mileage: -8.0, Hours of flight: 20.5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
