CREATE A BOARDING SCHEDULER Your boarding scheduler program will consist of thre
ID: 3711559 • Letter: C
Question
CREATE A BOARDING SCHEDULER
Your boarding scheduler program will consist of three classes: Passenger, BoardingHeap, and BoardingScheduler. The Passenger class represents a single passenger, including all information about that passenger. The BoardingHeap is a heap implementation of a priority queue with Passengers as elements. The BoardingScheduler is the main engine that runs your program.
1. CREATE PASSENGER CLASS
First, let’s define a simple Passenger class. Each passenger is created with up to four properties: name, check-in time, seat, and an optional preferredBoarding number. The check-in desk has asked you to make the following public constructors available:
public class Passenger implements Comparable<Passenger> {
public Passenger(String name, int time, String seat);
public Passenger(String name, int time, String seat, int preferredBoarding);
public void setDoneTimeEstimate(int estimate) {
}
public int compareTo(Passenger other) {
} //Required for implementing Comparable
}
The following private fields must be included. You may create additional private fields
name: The name of the passenger.
time: The time a passenger checked in, as a number in minutes after the airport opened for business that day.
seat: This string indicates the seat number of the passenger. (Examples: “2A”, “15D”) The check-in desk sends this to you as a string, but you only need the numeric part for calculating priority.
preferredBoarding: This number indicates extra priority that a passenger may have bought at the check-in desk. Higher numbers indicate higher priority. A passenger without a preferredBoarding number is assigned a default 0.
You MAY create public accessor (getter) methods and/or public mutator (setter) methods for any fields in this class. You MUST create one particular mutator (setter) method called setDoneTimeEstimate, which you will use to store a passenger’s estimated boarding completion time (a component of their priority) as they are enqueued into the heap. You must also implement a compareTo method which you will use to determine whether two passengers should be swapped when enqueuing/dequeuing.
Explanation / Answer
package chegg;
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
public class Passenger implements Comparable<Passenger>{
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSeat() {
return seat;
}
public void setSeat(String seat) {
this.seat = seat;
}
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
public int getPreferredBoarding() {
return preferredBoarding;
}
public void setPreferredBoarding(int preferredBoarding) {
this.preferredBoarding = preferredBoarding;
}
private String name;
private String seat;
private int time;
private int preferredBoarding;
public Passenger(String name,int time,String seat)
{
this.name=name;
this.time=time;
this.seat=seat;
this.preferredBoarding=0;
}
public Passenger(String name,int time,String seat,int preferredBoarding)
{
this(name, time, seat);
this.preferredBoarding=preferredBoarding;
}
public int compareTo(Passenger other)
{
return (other.preferredBoarding>this.preferredBoarding)?1:0;
}
}