Question: java please Question 3-2 Add a compreTo method to the Passenger class that you created for the previous assignment. Passengers should be compared based on
java please Question 3-2
Add a compreTo method to the Passenger class that you created for the previous assignment. Passengers should be compared based on their last names. If two passengers have the same last name then the seat numbers must be compared.
Solution
public int compareTo(Object o) { Passenger p = (Passenger)o; //checking to see if the last names are the same, if it is then compare based on the seat number if (this.getLast().equalsIgnoreCase(p.getLast())) return this.seatNumber - p.seatNumber; else return this.getLast().compareTo(p.getLast()); //if the last names are not the same then compare the last names }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
