Question: Need help with this java homework, use public class Plane extends Airline please. Thank you. Exercise 1 Implement the following UML diagram. Airline - totalPlanes

Need help with this java homework, use public class Plane extends Airline please. Thank you.

Exercise 1

Implement the following UML diagram.

Airline

- totalPlanes : int

- name : String

- allPlanes : Plane [ ] //an array of Planes

+ Airline (name : String)

+ getName () : String

+ getTotalPassengers ( ) : int //goes through allPlanes array to get all Passengers

+ getTotalPlanes ( ) : int

+ getAllPlanes ( ) : [ ] Plane

+ setName (n : String) : void

+ addPlane (p : Plane) : void //adds a Plane object to the allPlanes array, update totalPlanes

+ percentageFull ( ) : double //compares the number of passengers with number of seats for all planes

+ toString ( ) : String

Plane

- planeName : String //flight name (e.g., AC123)

- numSeats : int //number of seats on the plane

- numPassengers : int //number of passengers who bought a ticket

+ Plane (name : String, numSeats : int)

+ getNumSeats ( ) : int

+ getNumPassengers ( ) : int

+ setNumSeats (num : int) : void

+ addPassengers (num : int) : void //if room on plane, num passengers are added

+ hasMoreSeats (p : Plane) : boolean //returns true/false if 'this' Plane has more seats than p

+ toString ( ) : String

Notes on the classes:

Airline class

The constructor in the Airline class sets name, initializes the totalPlanes to 0, and initializes the array to hold 10 planes.

The Airline toString method returns the name of the Airline, total number of planes, and the total number of passengers that have flown on all their planes.

The addPlane method adds a Plane object to the array of Planes that the Airline has

percentageFull returns numberOfAllPassengers / numberOfAllSeats in the Planes in the airline to see how full all the planes are.

Plane class

The constructor sets the name of the plane (flight name), the total number of seats on the plane and sets numPassengers to 0

addPassenger method increases the numPassengers by the number num (do appropriate checks in this method)

hasMoreSeats (Plane p) compares two Plane objects (this Plane and Plane p) to see which one has more seats on the plane (ie., see which one is bigger).

Properly test your classes by performing the following operations in a demo class, at minimum.

Create an Airline class with at least 3 Plane objects. Add passengers to all the Planes. Add the planes to your airline. Print out the totalNumber of planes that the airline has. Print out the total number of passengers on all the planes (use the method getTotalPassengers in the Airline class). Add some more passengers to your second plane. Print out the percentageFull (totalPassengers from all planes / totalSeats from all planes) on all the Planes. Print out the plane object that has the most seats. Call the toString method in the Airline Class.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!