Question

In: Computer Science

I want to write this program in java. Write a simple airline ticket reservation program in...

I want to write this program in java.

Write a simple airline ticket reservation program in java.The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit on the number of flights. Create a linked list of flights with each node including a pointer to a linked list of passengers.

Solutions

Expert Solution

package elastic5.elastic5;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import elastic5.elastic5.ttt.Console;

public class AirlineRes extends JFrame {
   static final int MAX_SEATS = 8;
   String[] seats = new String[MAX_SEATS];
public AirlineRes() {

initUI();
}

private void initUI() {
  
createMenuBar();

setTitle("airline ticket reservation");
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}

private void createMenuBar() {

JMenuBar menubar = new JMenuBar();
ImageIcon icon = new ImageIcon("exit.png");

JMenu file = new JMenu("File");
file.setMnemonic(KeyEvent.VK_F);

JMenuItem eMenuItem = new JMenuItem("Exit", icon);
eMenuItem.setMnemonic(KeyEvent.VK_E);
eMenuItem.setToolTipText("Exit application");
eMenuItem.addActionListener((ActionEvent event) -> {
System.exit(0);
});

file.add(eMenuItem);
  
//reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers
JMenuItem eMenuItem1 = new JMenuItem("Reserve Ticket", icon);
eMenuItem1.setMnemonic(KeyEvent.VK_E);
eMenuItem1.setToolTipText("Book Ticket");
eMenuItem1.addActionListener((ActionEvent event) -> {
   String[] seats = new String[MAX_SEATS]; // the passenger list
initializeSeats(seats);
   makeReservation(seats);
System.out.println("book ticket");
});

file.add(eMenuItem1);


JMenuItem eMenuItem2 = new JMenuItem("cancel a reservation", icon);
eMenuItem2.setMnemonic(KeyEvent.VK_E);
eMenuItem2.setToolTipText("cancel a reservation");
eMenuItem2.addActionListener((ActionEvent event) -> {
  
   try {
       String[] seats = new String[MAX_SEATS]; // the passenger list
initializeSeats(seats);
               cancelReservation(seats);
              
           } catch (Exception e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
           }
System.out.println("cancel a reservation");
});

file.add(eMenuItem2);
  
JMenuItem eMenuItem3 = new JMenuItem("check whether a ticket is reserved for a particular person", icon);
eMenuItem3.setMnemonic(KeyEvent.VK_E);
eMenuItem3.setToolTipText("check whether a ticket is reserved for a particular person");
eMenuItem3.addActionListener((ActionEvent event) -> {
System.out.println("check whether a ticket is reserved for a particular person");
});

file.add(eMenuItem3);
  
JMenuItem eMenuItem4 = new JMenuItem("display the passengers", icon);
eMenuItem4.setMnemonic(KeyEvent.VK_E);
eMenuItem4.setToolTipText("display the passengers");
eMenuItem4.addActionListener((ActionEvent event) -> {
System.out.println("display the passengers");
});

file.add(eMenuItem4);
  
menubar.add(file);

setJMenuBar(menubar);
}

  
  
static void initializeSeats(String[] seats) {
for (int i = 0; i < seats.length; i++) {
seats[i] = "";
}
}
  
/**
* Make a reservation
*/
void makeReservation(String[] seats) {
int seatIndex = findEmptySeat(seats); // index of first empty seat
if (seatIndex == seats.length) {
System.out.println("All seats are full. Sorry.");
} else {
String name = getPassengerName(); // passenger's name
seats[seatIndex] = name;
System.out.println(name + " has been assigned seat #" + (seatIndex+1));
}
}
/**
* Find the index of the first empty seat on the plane.
* If there are no empty seats, return seats.length
*/
int findEmptySeat(String[] seats) {
for (int i = 0; i < seats.length; i++) {
if (isEmpty(seats, i)) {
return i;
}
}

return seats.length;
}
boolean isEmpty(String[] seats, int seatIndex) {
return seats[seatIndex].equals("");
}
  
/**
* Cancel a reservation
* @throws IOException
* @throws NumberFormatException
*/
void cancelReservation(String[] seats) throws NumberFormatException, IOException {
int seatIndex = getSeatToCancel(); // index of seat to cancel reservation for
if (isEmpty(seats, seatIndex)) {
System.out.println("Seat #" + (seatIndex+1) + " has not been reserved for anyone");
} else {
seats[seatIndex] = "";
System.out.println("Seat #" + (seatIndex+1) + " is now available");
}
}
  
  
int readInt() throws NumberFormatException, IOException {
int i = 0;

boolean valid = false;
i=2;
// i = Integer.parseInt(in.readLine());
valid = true;

System.out.print("ttt");

return i;
}

int getSeatToCancel() throws NumberFormatException, IOException {
boolean valid = false; // is the seat number valid?
int seat; // seat number to cancel

do {
System.out.print("Enter the seat to cancel: ");
seat = readInt();
if (1 <= seat && seat <= MAX_SEATS) {
valid = true;
} else {
System.out.println("Invalid seat number");
}
} while (!valid);

return seat-1;
}
  
String getPassengerName() {
System.out.print("Enter the passenger's name: ");
return "Parmesh dayal";
}
  
public static void main(String[] args) {
   boolean done = false;
     
String[] seats = new String[MAX_SEATS]; // the passenger list
initializeSeats(seats);
EventQueue.invokeLater(() -> {
AirlineRes ex = new AirlineRes();
ex.setVisible(true);
});
}}


Related Solutions

Write a simple airline ticket reservation program. The program should display a menu with the following...
Write a simple airline ticket reservation program. The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit on the number of flights. Create a linked list...
Java I'm trying to create a program that replicates a theater ticket reservation system. I have...
Java I'm trying to create a program that replicates a theater ticket reservation system. I have a Seat class with members row(integer), seat(character) and ticketType(character). Where a ticket type can be 'A' adult, 'C' child, 'S' senior, or '.' recorded as empty. I have a Node generic class that points to other nodes(members): up, Down. Left, Right. It also has a generic payload. Lastly, I have an Auditorium class which is also generic. its member is a First Node<T>. As...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
in a gui ' in java write a program that draws equal a simple fence with...
in a gui ' in java write a program that draws equal a simple fence with vertical, spaced slats backed by two boards. Behind the fence show a simple house support Make sure the in the und. house is visible between the slats in the fence.
What we want the program to do: We need to write a program, in Java, that...
What we want the program to do: We need to write a program, in Java, that will let the pilot issue commands to the aircraft to get it down safely on the flight deck. The program starts by prompting (asking) the user to enter the (start) approach speed in knots. A knot is a nautical mile and is the unit used in the navy and by the navy pilots. After the user enters the approach speed, the user is then...
I want this program written in JAVA with the algorithm(The step by step process for the...
I want this program written in JAVA with the algorithm(The step by step process for the problem) . Please help it is due in a couple of hours. I don't want the C++ program, I want it in JAVA please #20 Theater Ticket Sales Create a TicketManager class and a program that uses it to sell tickets for a single performance theater production. Here are the specifications: • The theater's auditorium has 15 rows, with 30 seats in each row....
Java For this project, we want to build a calculator program that can perform simple calculations...
Java For this project, we want to build a calculator program that can perform simple calculations and provide an output. If it encounters any errors, it should print a helpful error message giving the nature of the error. You may use any combination of If-Then statements and Try-Catch statements to detect and handle errors. Program Specification Input Our program should accept input in one of two ways: If a command-line argument is provided, it should read input from the file...
An airline company is designing a new online reservation system. They want to add some direct-manipulation...
An airline company is designing a new online reservation system. They want to add some direct-manipulation features. For example, they would like customers to click a map to specify the departure cities and the destinations, and to click on the calendar to indicate their schedules. From your point of view, list two benefits and two problems of the new idea compared with their old system, which required the customer to do the job by typing text. (Answer in 400 -...
An airline reservation system suffers a 10% rate of no-shows. A new reservation system is then...
An airline reservation system suffers a 10% rate of no-shows. A new reservation system is then instituted in hopes of REDUCING this no-show rate. After implementation of the new procedure, a SRS of 2500 reservations showed a 10.24% (256 out of 2500) no-show rate. A) what is the population? B) variable of interest? C)what are the null and alternative hypotheses? D)determine the value of the appropriate observed test statistic to perform this test (note: 10.24%=0.01024 & 10%=0.1000) E)whats the p-value?
In this question, you are asked to write a simple java program to understand natural language....
In this question, you are asked to write a simple java program to understand natural language. The user will enter the input following the format: Name came to City, Country in Year. For example: Robin came to Montreal, Canada in 2009. Assume a perfect user will follow the exactly above formats for the inputs. Your program should be able to analyze the key words (Name, City, Country and Year) from the inputs and reorganize the outputs following format: Name stay...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT