Question: Q5) Write a complete Java program that defines the following: 1) Class Passenger with the following specifications: Instance variables: name: name of the passenger of

 Q5) Write a complete Java program that defines the following: 1)

Q5) Write a complete Java program that defines the following: 1) Class Passenger with the following specifications: Instance variables: name: name of the passenger of type string ticketPrice: price of the passenger's ticket of type double Methods: full-parameterized constructor: a constructor method used to initialize the instantiated objects toString(): return name and ticket price of the passenger 2) class Flight with the following specifications: Instance variables: noOfSeats: number of available seats of type integer date: date of the flight of type java.util.Date passengers: array of passengers of type Passenger for a given flight. Use ArrayList for simplicity Methods: full-parameterized constructor: a constructor method used to initialize the instantiated objects Flight (int noofSeats, Date date) addPassenger(Passenger p): add passenger to the ArrayList passengers. Use add() method of ArrayList to add passebgers. Addition of passengers should not exceed the number of available seats (noOfSeats). sum(): return the sum of prices of all tickets toString(): return the date and passengers (name, ticket price) of the flight 3) Driver class that creates an object of type Flight, add passengers to it, and finally print the object's date, passengers, and total price of all tickets. The output should look like the following: Sorry Ahmed the flight is fully booked Flight Data: Date (02/3/2021) [ (Mohammed, 2500.0), (Yaser, 3500.0)] Total tickets price: 6000.0

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!