Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the class Passenger which includes: a) 3 attributes: passport number (which is unique), name and age. b) a zero-arg constructor and a mutli-arg constructor.

Write the class Passenger which includes: a) 3 attributes: passport number (which is unique), name and age. b) a zero-arg constructor and a mutli-arg constructor. c) getters for name and age attributes. d) toString() method which overrides the Object's toString() method. e) equals() method which overrides the Object's equals() method. 2. Write the class Flight which includes: a) 2 attributes: flight number and ArrayList of Passengers. b) one-arg constructor that accepts (as an argument) the flight number, and create a new empty ArrayList of Passengers. c) method addPassenger() that accepts a Passenger and add it to the ArrayList with a confirmation message. It is not allowed to add the same passenger twice and in this case an error message should be displayed. d) method oldestPassenger() which returns the name of oldest Passenger in the flight (whose age is the maximum). e) method saveIntoFile() which accepts a file name. It stores the flight number and information of all Passengers in this file (each passenger in a different line). 3. Write a code to test your classes by performing the following tasks: a) create a Flight object called myFlight where the flight number is 251. b) add 2 Passengers to myFlight using the method addPassenger() c) print the name of oldest Passenger in the flight by calling the method oldestPassenger() d) call the method saveIntoFile() to save the required information.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions