PLEASE I NEED HELP WITH THIS JAVA CODE
Homework 3-3
Create a Driver class to use your Airplane and Passenger classes and create instances of them.
In the main method do the following:
Create an Airplane that will store up to 100 Passengers
Create 5 Passenger Objects with the details specified in the table below
Add the 5 Passenger objects to the Airplane
Call the printDetails method from the Airplane to print all the Airplane and Passenger details.
variable name |
name |
birthYear |
weight |
gender |
p1 |
Albert |
1879 |
198.5 |
‘m’ |
p2 |
Grace |
1906 |
105 |
‘f’ |
p3 |
Tim |
1955 |
216.3 |
‘m’ |
p4 |
Steve |
1955 |
160 |
‘m’ |
p5 |
Sergey |
1973 |
165.35 |
‘m’ |
This work must be completed in your textbook ZYBooks -- CMP-168: Programming Methods II
No other forms of submission will be accepted.
/*The java program that tests the class Airplane by adding
the passengers to the airplane object
* and then display the passenger objects to console output
window.*/
//Tester.java
public class Tester {
public static void main(String[] args) {
//create an instance of Airplane
with size,100
Airplane airplane=new
Airplane(100);
//add passenger objects to the
airplane
airplane.addPassenger(new
Passenger("Albert", 1879, 198.5, 'm'));
airplane.addPassenger(new
Passenger("Grace", 1906, 105, 'f'));
airplane.addPassenger(new
Passenger("Tim", 1955, 216.3, 'm'));
airplane.addPassenger(new
Passenger("Steve", 1955, 160, 'm'));
airplane.addPassenger(new
Passenger("Sergey", 1973, 165.35, 'm'));
//call display method to print the
passengers to console output
airplane.display();
}
}
--------------------------------------------------------------------------------------------------------------
//Airplane.java
public class Airplane
{
private Passenger passengers[];
private int count;
//constructor with size
public Airplane(int size)
{
passengers=new
Passenger[size];
count=0;
}
//Add passenger to the passengers array
public void addPassenger(Passenger p)
{
passengers[count]=p;
count++;
}
//Method to display the passengers
public void display()
{
System.out.printf("%-20s%-10s%-10s%-10s\n",
"Name","Year","Weight","Gender");
for (int i = 0; i < count;
i++)
{
System.out.println(passengers[i].toString());
}
} //end of the method ,display
} //end of the class
--------------------------------------------------------------------------------------------------------------
//Passenger.java
public class Passenger
{
private String name;
private int year;
private double weight;
private char gender;
/*constructor with the arguments*/
public Passenger(String name, int year, double weight,
char gender) {
this.name = name;
this.year = year;
this.weight = weight;
this.gender = gender;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public char getGender() {
return gender;
}
public void setGender(char gender) {
this.gender = gender;
}
@Override
public String toString() {
return
String.format("%-20s%-10d%-10.2f%-5c",
name,year,weight,gender);
}
}
--------------------------------------------------------------------------------------------------------------
sample output:
PLEASE I NEED HELP WITH THIS JAVA CODE Homework 3-3 Create a Driver class to use...