I need help !!!!!!
Hi,
I have a big question here. It has 4 parts. I already finished two parts, and I get stuck in the third part because I don't know how to set up the two constructors and
write the methods. Below is the whole question and my codes to the first two parts
For this question, you will be writing 4 classes. You are required to put each class in its own
file, and so you should submit 4 Java files. The first 3 classes are worth 3 marks each, and the
driver class, AirlineTester, is worth 1 mark.
You will be implementing a basic model for an Airline, including the classes for Airports,
Flights, and Passengers. Finally, you will implement a driver that tests the other classes to ensure
that they are working correctly. Each class is described in detail below. Unless otherwise
specified, make all instance variables private, and all of the specified methods should be
made public. You may also create helper methods if you like, but all methods other than
those specified must be made private.
(a) The Airport class represents and airport. Every airport has a name (such as 揔ennedy
International Airport?, an airport code (such as 揓FK?, and a location (such as 揘ew
York, NY?. Implement a constructor that lets you set these three properties when the
object is created. For each of these instance variables, implement a getter, but since
none of these variables are likely to change, do not implement setter methods for any
of them.
Write a toString method that returns the name, code, and location of the airport in a format
such as:
Kennedy International Airport (JFK): New York, NY
(b) the Passenger class represents a passenger. Every passenger has a first name, last
name, and age. Write a constructor that takes all three of these values and sets them
appropriately, and write getters for all three variables. Since none of these values are
likely to change, do not write setters for these variables, but write a toString method that
returns the information in a nice format, such as:
Name: Joe Smith
Age: 35
3
(c) The Flight class represents a flight between two airports. Every flight has a flight
number, two Airport objects, one for the origin and one for the destination of the
flight, as well as up to 5 passengers. Since we are just starting to learn about Arrays, you
may use an Array to keep track of the passengers, or you may use 5 instance variables
(though in the next assignment, you will be working with these same classes, and you
will be required to use Arrays, so you might want to try using them for this assignment).
Write two constructors, one which takes just the flight number, and one that takes the
flight number and the two airports. Write getters for all of the variables except for the list
of passengers. Write setters for the origin and destination airports, and write a method
called addPassenger that takes a Passenger object and returns a boolean value indicating
whether the passenger was added to the flight. The method should try to add
the passenger to the list of passengers, and return true if successful, or false if there are
already 5 passengers on the flight.
Also write a method called numPassengers that returns the number of passengers on
the flight.
Write a method called toString that prints out the flight information. If either the origin or
destination airport has not been set, output the value 揘ot Set?in its place. An example
of the output of toString is as follows:
Flight Number: 1234
From: Kennedy International Airport (JFK): New York, NY
To: Not Set
2 Passenger(s):
Name: Joe Smith
Age: 35
Name: Jane Smith
Age 33
(d) The AirlineTester class is a driver class, and contains just a main method. The main
method must create 6 passenger objects, 3 airport objects, and 2 flight objects. Give all
of the objects different values, so they are all unique.
Make sure that you test all of the methods (including all getters and setters, and constructors)
of each class at least once. Also, make sure that you test that the Flight toString
method will print out 揘ot Set?if an airport is not set for either the source or destination.
Show that the Flight addPassenger method will properly return false if the flight is
already full. The point of this question is to prove to us that everything works as it should,
so think about how best to do this.
// This is the Airport Class.
// The Airport class represents an airport.
publicclass Airport
{
private String Name;
private String Code;
private String Location;
// This is the constructor. It has three parameters.
public Airport (String AirportName, String AirportCode, String AirportLocation)
{
Name = AirportName;
Code = AirportCode;
Location = AirportLocation;
}
// The following three methods are the Getter methods.
public String getName()
{return Name;}
public String getCode()
{return Code;}
public String getLocation()
{return Location;}
// This is the toString method which returns the whole name of the airport and the location.
public String toString ()
{
String s = Name +" " +"(" + Code +")" +" : " + Location;
return s;
}
}
// This is the Passenger class.
// This class represents a passenger.
publicclass Passenger
{
private String firstName;
private String lastName;
private String age;
// This is the constructor.
public Passenger(String first_Name, String last_Name, String p_Age)
{
firstName = first_Name;
lastName = last_Name;
age = p_Age;// The variable name "p_Age" means "passenger's age".
}
// The following three methods are getter methods.
public String getFirstName ()
{return firstName;}
public String getLastName ()
{return lastName;}
public String getAge ()
{return age;}
// This is the toString method that returns the information.
public String toString ()
{
String Name ="Name:" +" " + firstName +" " + lastName;
String Age ="Age:" +" " + age;
String result = Name +"\n" + Age;
return result;
}
}

