Question: 1 . Write a Passenger class with private data for passenger name and priority ( 1 , 2 ) with natural ordering from the Comparable

1. Write a Passenger class with private data for passenger name and priority (1,2) with natural ordering
from the Comparable interface defined by the priority level.
2. Fill in the missing code in the App.java program to fill the priority queue with passenger data,
complete the GUI form showing seats, and fill in remaining code as marked by the // TODO: comments.
Be sure to test your code on both data sets, passengers1.txt and passengers2.txt. You do not have to
do data validation unless you wish so can assume normal and valid data. Code for InitalApp class: package school.assg;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.geometry.Pos;
import javafx.geometry.Insets;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.paint.Color;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import java.io.*;
import java.util.PriorityQueue;
import java.util.Scanner;
public class AppInitial extends Application {
// priority queue of passengers
// priority 1 is first class, priority 2 is economy
private PriorityQueue passengers = new PriorityQueue<>();
private Button [][] seats = null; //2D array of buttons that represent the seats
private TextField passengerTextField; // displays passenger name
private final int WIDTH =15; // width of text for button
private int nrows, ncolumns; // number of rows and columns
private String blankString; // string of WIDTH spaces
@Override
public void start(Stage stage){
Scanner filescan = null;
try
{ filescan = new Scanner (new File("passengers1.txt"));
}
catch (IOException e)
{ System.out.println ("open error");
System.exit(1);
}
nrows = filescan.nextInt(); // number of rows
ncolumns = filescan.nextInt(); // number of columns
filescan.nextLine(); // extract newline
// fonts for the buttons and top label
Font fontlabel = Font.font("Monospaced", FontWeight.EXTRA_BOLD, 25);
Font fontbutton = Font.font("Monospaced", FontWeight.EXTRA_BOLD, 12);
seats = new Button [nrows][ncolumns]; // make the 2D array of buttons
blankString ="".repeat(WIDTH); // string of blanks
// make the buttons
for (int r=0; r { processPassenger(); });
passengerTextField = new TextField();
passengerTextField.setEditable(false);
// exit button
Button exitButton = new Button ("Exit");
exitButton.setOnAction(event ->{ System.exit(0); });
// add content to left pane
leftPane.getChildren().add(processButton);
leftPane.getChildren().add(passengerTextField);
leftPane.getChildren().add(exitButton);
leftPane.setAlignment(Pos.TOP_CENTER);
leftPane.setPadding(new Insets(25,25,25,25));
// add the left pane to the outer pane
outerpane.setLeft(leftPane);
// center pane is a GridPane
GridPane centerPane = new Gri

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!