FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
1. FedExPlanes7.txt
1 medical 111 Boeing767 120000 London
3 packages 555 MD11 180000 Barcelona
4 animals 444 MD11 30000 Miami
6 animals 333 Boeing757 60000 Jackson
7 packages 666 Boeing777 230000 Seattle
9 medical 222 Boeing767 100000 Frankfurt
10 packages 777 Boeing757 90000 Austin
FedExTrucks7.txt
1 688 Memphis
3 820 Denver
4 728 Dallas
Assignment4.java
import java.util.*;
import java.io.*;
public class Assignment4 {
public static void main(String[] args) throws IOException {
//creates plane & truck file objs + cargo terminal
Scanner planeFile = new Scanner(new File("FedExPlanes.txt"));
Scanner truckFile = new Scanner(new File("FedExTrucks.txt"));
CargoTerminal terminal = new CargoTerminal(truckFile.nextInt(),
planeFile.nextInt());
//add semiTrucks into terminal
System.out.println("Loading semi-trucks and planes into cargo
terminal...n");
while(truckFile.hasNext()) {
int dock = truckFile.nextInt();
int number = truckFile.nextInt();
String destination = truckFile.next();
terminal.addSemiTruck(dock, new SemiTruck(number, destination));
}
truckFile.close();
//add planes into terminal
while(planeFile.hasNext()) {
int stand = planeFile.nextInt();
2. int flight = planeFile.nextInt();
String type = planeFile.next();
double capacity = planeFile.nextDouble();
String destination = planeFile.next();
terminal.addCargoPlane(stand, new CargoPlane(flight, type,
capacity, destination));
}
planeFile.close();
//display planes and trucks
terminal.displayTrucksAndPlanes();
//print tarmac report
System.out.println("Flight tt Stand tt Deparing To tt Type tt
Capacity(lbs)tt n"
+
"----------------------------------------------------------------------------------
----n");
printTarmacStatus(terminal);
}
//status report method for tarmac
public static void printTarmacStatus(CargoTerminal terminal) {
ArrayList reports = new ArrayList();
for(int i = 0; i < terminal.getNumStands(); i++) {
//get plane obj and store vars for report
CargoPlane temp;
if(terminal.getCargoPlane(i) != null) {
temp = terminal.getCargoPlane(i);
int flight = temp.getNumber();
String type = temp.getType();
double capacity = temp.getCapacity();
String destination = temp.getDestination();
reports.add(new PlaneReport(i, flight, type, capacity,
destination));
}
}
Collections.sort(reports);
3. for(int i = 0; i < reports.size(); i++) {
PlaneReport report = reports.get(i);
System.out.println(report.print());
}
}
}
//define printable interface with abstract method
interface Printable {
public abstract String print();
}
//define cargo terminal class
class CargoTerminal {
private int numberDocks;
private int numberStands;
private SemiTruck[] loadingDock;
private CargoPlane[] tarmac;
//define constructor
public CargoTerminal(int numberDocks, int numberStands) {
this.numberDocks = numberDocks;
this.numberStands = numberStands;
this.loadingDock = new SemiTruck[numberDocks];
this.tarmac = new CargoPlane[numberStands];
}
//define getter methods
public int getNumDocks() {
return this.numberDocks;
}
public int getNumStands() {
return this.numberStands;
}
//add to dock/stand
public void addSemiTruck(int dock, SemiTruck semiTruck) {
this.loadingDock[dock] = semiTruck;
}
public void addCargoPlane(int stand, CargoPlane cargoPlane) {
this.tarmac[stand] = cargoPlane;
4. }
//truck/plane getters
public SemiTruck getSemiTruck(int dock) {
if(this.loadingDock[dock] != null) {
return this.loadingDock[dock];
}else {
return null;
}
}
public CargoPlane getCargoPlane(int stand) {
if(this.tarmac[stand] != null) {
return this.tarmac[stand];
}else {
return null;
}
}
//print trucks & planes
public void displayTrucksAndPlanes() {
for(int i = 1; i < getNumDocks(); i++) {
System.out.print("Dock # " + i + " t");
}
System.out.print('n');
for(int i = 1; i < getNumDocks(); i++) {
if(this.loadingDock[i] != null) {
System.out.print(this.loadingDock[i].getNumber() + " t
t");
}else {
System.out.print("----- tt");
}
}
System.out.println('n');
for(int i = 1; i < getNumStands(); i++) {
System.out.print("Stand # " + i + " t");
}
System.out.print('n');
5. for(int i = 1; i < getNumStands(); i++) {
if(this.tarmac[i] != null) {
System.out.print(this.tarmac[i].getNumber() + " tt");
}else {
System.out.print("----- tt");
}
}
System.out.println('n');
}
}
//define semiTruck class
class SemiTruck{
private int truckNumber;
private String destinationCity;
public SemiTruck(int truckNumber, String destinationCity) {
this.truckNumber = truckNumber;
this.destinationCity = destinationCity;
}
public int getNumber() {
return this.truckNumber;
}
public String getDestination() {
return this.destinationCity;
}
}
//define cargoPlane class
class CargoPlane{
private int flightNumber;
private String type;
private double capacity;
private String destinationCity;
//public constructor
public CargoPlane(int flightNumber, String type, double capacity,
String destinationCity) {
this.flightNumber = flightNumber;
6. this.type = type;
this.capacity = capacity;
this.destinationCity = destinationCity;
}
//define getters
public int getNumber(){
return this.flightNumber;
}
public String getType() {
return this.type;
}
public double getCapacity() {
return this.capacity;
}
public String getDestination() {
return this.destinationCity;
}
}
//define planeReport class & implement printable + comparable.
class PlaneReport implements Printable, Comparable{
private int stand;
private int flightNumber;
private String type;
private double capacity;
private String destinationCity;
//constructor
public PlaneReport(int stand, int flightNumber, String type, double
capacity,
String destinationCity) {
this.stand = stand;
this.flightNumber = flightNumber;
this.type = type;
this.capacity= capacity;
this.destinationCity = destinationCity;
}
//defining abstract methods
7. @Override
public String print() {
return String.format("%4dtt%2dtt%-15stt%-10st%.2f",
flightNumber, stand, destinationCity, type, capacity);
}
@Override
public int compareTo(PlaneReport otherReport) {
if(capacity > otherReport.capacity) {
return 1;
}
else if (capacity == otherReport.capacity) {
return 0;
}
else {
return -1;
}
}
}
Please Help me on this one. I really appreciate ( Its urgent)! 3. Write a test program (i.e. main) to
do the following: a. Setup steps from assignment 4. These are the same! Use your code or the
solution code on Canvas. i. Create a cargo terminal object ii. Read semi-trucks from
FedExTrucks7.txt (no changes) iii. Create semi-trucks and add to the cargo terminal's loading
dock iv. Read cargo planes from FedExPlanes7.txt (contains one update to cargo planes -
cargoType) v. Create cargo planes and add to the cargo terminal's tarmac vi. Print all semi-trucks
and cargo planes after loading cargo terminal is complete b. Start simulation (new steps for
assignment 7) i. Step 1: Create an air traffic controller object, a taxiways object, and a runaway
object ii. Step 2: Air traffic controller moves all planes in cargo terminal's tarmac to taxiways: -
Move planes from tarmac to taxiways based on taxiway rules (see below) - Print "Moved to
taxiway" message for cargo plane - see output below - Use controller's movePlanesToTaxiways
method. iii. Step 3: After all planes are moved, show that the cargo terminal's tarmac is empty.
iv. Step 4: Air traffic controller moves all planes waiting in taxiways to runway: - Move planes
in taxiways to runway based on runway rules (see below) - Print a "Moved to runway" message
for each plane - see output below - Use controller's movePlanesToRunway method. v. Step 5:
Air traffic controller simulate planes taking off: - After all planes are on the runway, clear each
plane for takeoff - Print a "cleared for takeoff" message for each plane - see output below - Use
8. controller's clearedForTakeoff method. 4. Test file information: a. Run your code on the updated
file FedExPlanes7.txt. This is a test file, do NOT ASSUME that the order or number of cargo
planes will be the same in the file used for grading. b. File layout is the same except a cargo type
(medical, animals, packages) was added to each plane: Stand # Cargo Type Flight# Type of
Plane Capacity Destination 1 medical 7654 Boeing767 120000 London
Updates to Existing Classes Remove some classes from Assignment 4 , reuse others.
Cargoterminal - Add one new public method: - public CargoPlane removeCargoPlane (int stand)
- Returns and removes the cargo plane stored in the tarmac at the specific stand (slot) - If there is
no cargo plane in stand location (i.e. empty array location), returns null - If there is a cargo plane,
return cargo plane and set location to null. CargoPlane - Must implement Comparable so cargo
planes can be placed into urgent taxiway priority queue. - Add new private data field -
cargoType - string with values medical, animals, and packages - Update constructor - include
cargoType field - Add new public methods isUrgent() - returns true if plane's cargo type is
"medical" or "animals" - isstandard () - returns true if plane's cargo type is "packages" - print() -
displays plane's flight number, destination city, and cargo type public int compareTo(CargoPlane
otherPlane) - Compare planes based on cargo type (medical or animals). - Medical cargo has
highest priority. - See the Tips section for details on comparing planes. New Classes Add three
new classes to cover new entities in the conceptual model: Taxiways, Runway &
AirTrafficController Taxiways - Description - Represents the 2 queues that make up the
taxiways - Private Data Fields - urgentTaxiway - a priority queue of cargo planes whose cargo
type is medical or animal - standardTaxiway - a regular queue of cargo planes whose cargo type
is packages
- Private Data Fields - urgentTaxiway - a priority queue of cargo planes whose cargo type is
medical or animal - standardTaxiway-a regular queue of cargo planes whose cargo type is
packages - Public Methods - Constructor public Taxiways() - Allocate memory for the 2 queues -
Add these new public methods: - isUrgentTaxiwayEmpty - returns true when urgent taxiway
queue is empty - addPlaneToUrgentTaxiway - adds (offers) plane to urgent queue -
removePlaneFromUrgentTaxiway - removes plane from urgent queve - Create the same isEmpty,
add, remove methods for standard taxiway queue Runway - Description - Represents the 1 queue
that makes up the runway - Private Data Fields - runway - a regular queue of cargo planes -
Public Methods - Constructor public Runway() - Allocate memory for the 1 queue - Add these
new public methods: - Create the isEmpty, add, remove methods for runway queue
AirTrafficController - Description - Contains the business logic for moving cargo planes from
tarmac to taxiways then to runway. - Private Date fields - None - Public Methods - Constructor:
9. none - public void movePlanesToTaxiways (CargoTerminal cargoTerminal, Taxiways taxiways)
- During setup, cargo planes were placed into the cargoTerminal (assignment 4 code). - Move
each plane from tarmac to taxiway based on taxiway rule #1 and #2 (see below)
- When moving a plane to correct taxiway, print a message with taxiway name, flight number,
destination city, and cargo type: Moved to taxiway Urgent flight: 654 London medical Moved to
taxiway Standard flight: 234 Barcelona packages - Rule 1: Planes must be removed from tarmac
in the order of their stands. So, the plane at stand 1 must be removed 11:, then plane at stand 2 ,
etc. - Rule 2: Planes must be moved to the correct taxiway based on cargo type. - If cargo type is
medical or animals - place into urgent taxiway. - If cargo type is packages - place into standard
taxiway. - For the example file, flight 654 to London with medical cargo goes to urgent taxiway,
while flight 234 to Barcelona with packages goes to standard taxiway. - public void
movePlanesToRunway (Taxiways taxiways, Runway runway) - Move planes from taxiways to
runway based on runway rule #1 (see below). - When moving a plane, print message with flight
number, destination city, and cargo type. Moved to runway flight: 654 London medical - Rule 1:
Move planes to the runway based on urgency. - 1rz move planes in urgent taxiway to runway. -
2nd move planes in standard taxiway to runway. - Note: UrgentTaxiway is a priority queue and
ordered by cargo type - Medical cargo has highest priority over animal cargo. - This means
planes carrying medical cargo are placed on the runway first. This is taken care of with the
compareTo method on the cargo plane. - public void clearedForTakeoff (Runway runway) -
Simulate the planes taking off. - Remove cargo planes from runway. - When planes take off,
print message with flight number, destination city, and cargo type: Cleared for takeoff flight: 654
London medical Tips Must Do - Use a priority queue for the urgent taxiway - Use regular queue
for standard taxiway and the runway Tip: Class Name Errors - If you copy your assignment 4
into a new file or use the code on canvas, rename your classes to avoid the error of "Class name
is already defined". For example, I renamed CargoTerminal to CargoTerminal7. Tip: Urgent
Taxiway - For the urgent taxiway (priority queue) to work the CargoPlane class must implement
Comparable - The compareTo method in the cargo plane class must compare the cargo type of
the cargo planes.
- Note: cargo type is a string - With strings, sorted order is normally based on alphabetical order.
- Because "ABD"