Java programing please help me Hello I tried making a Class
Java programing please help me. Hello, I tried making a Class Flight.
Write a Class called Flight that has four member data items:
number - the Flight Number, an integer
destination - The Flight\'s Destination, a string
status - the Status of the Flight, a char
(B=Boarding, D=Departed, L=Landed, O=Out of Service)
passengerList - The flight\'s list of passengers. ArrayList<String>
Write the constructor for initializing an object with an inital flight number,
destination, initial status = Boarding, and the passengerList instantiated
but empty
Write get methods for each Data member.
Write set methods for destination and status.
write an addPasssenger method.
Write a clearPassengers method.
Write an equals member method to compare two Flight objects,
and return true if their destinations are equal to each other, otherwise
it returns false.
Write a toString method that will display the values of the member data.
Solution
Flight.java
import java.util.ArrayList;
public class Flight {
private int number;
private String destination;
private char status;
ArrayList<String> passengerList ;
public Flight(int number, String destination){
this.number = number;
this.destination = destination;
status = \'B\';
passengerList = new ArrayList<String>();
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public char getStatus() {
return status;
}
public void setStatus(char status) {
this.status = status;
}
public int getNumber() {
return number;
}
public void addPasssenger(String passenger){
passengerList.add(passenger);
}
public void clearPassengers(){
passengerList.clear();
}
public boolean equals(Flight f){
if(this.destination.equals(f.destination)){
return true;
}
else{
return false;
}
}
public String toString(){
return \"Number: \"+getNumber()+\" Destination: \"+getDestination()+\" Status: \"+getStatus();
}
}

