Airline Reservation You must use Object Oriented Programming to design this proj
ID: 666092 • Letter: A
Question
Airline Reservation
You must use Object Oriented Programming to design this project.
Write a reservation system for an airline flight. Assume the airplane has 10 rows with 4 seats in each row. Use a two dimensional array of strings to maintain a seating chart. In addition create a array to be used as a waiting list in case the plane is full. The waiting list should be "first come first serve" that is people who are added early in the list get the priority over those who are added later. Allow the user to add three options
1. Add a passenger to the list.
a. Request the passenger's name.
b. Display a chart of the seats in the airplane in a tabular form
c. If seats are available let the passenger choose a seat. Add the passenger to the seating chart.
d. If no seats are available, place the passenger on the waiting list.
2. Remove a passenger from the list
a. Request the passengers name
b. Search the seating chart for the passenger's name and delete it.
c. If the waiting list is empty, update the array so that the seat is available,
d. If the waiting list is not empty remove the first person from the list, and give him or her the newly vacated seat.
3. Quit
You will need to use string methods defined in java.lang.String in the documentation reference.
String comparision function names are as follows
equal, equalIgnoreCase.
Explanation / Answer
AirLineReservation.java
package airlinereservation;
import java.util.Scanner;
/**
*
* @author lavanya.komarasamy
*/
public class AirLineReservation {
public static void main(String[] args) {
System.out.print("Welcome to Airline reservation system!");
String continu = "y";
AirPlan airPlan = new AirPlan();
do {
System.out.print("Options: 1.Reserve the ticket 2.Cancel the ticket 3.Quit the application");
Scanner sc = new Scanner(System.in);
char option = sc.nextLine().charAt(0);
switch (option) {
case ('1'):
airPlan.add();
break;
case ('2'):
airPlan.cancel();
break;
case ('3'):
airPlan.quit();
break;
}
System.out.print("Do you want to continue(y/n):");
continu = sc.nextLine();
} while ("y".equalsIgnoreCase(continu));
}
}
AirPlan.java
package airlinereservation;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author lavanya.komarasamy
*/
public class AirPlan {
Scanner sc = new Scanner(System.in);
String[][] sheats = new String[10][4];
ArrayList<String> waitingList = new ArrayList<String>();
int freeSheatNumber = 0;
public void show() {
int k = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 4; j++) {
if (sheats[i][j] == null) {
k++;
}
}
}
freeSheatNumber = k;
}
public void add() {
show();
if (freeSheatNumber == 0) {
System.out.print("Sheat are full. Do you like to add in Waiting list? (y/n)");
String wantToAdd = sc.nextLine();
if ("y".equalsIgnoreCase(wantToAdd)) {
addWaitingList();
} else {
quit();
}
}
System.out.print("Please Enter Passenger Name:");
String name = sc.nextLine();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 4; j++) {
if (sheats[i][j] == null) {
sheats[i][j] = name;
break;
}
}
break;
}
System.out.println("Ticket reserved successfully! Happy Journey" + name + "!");
show();
if (freeSheatNumber != 0) {
System.out.println(freeSheatNumber + " tickets are available.");
} else {
System.out.println("No tickets are available.You can add into Waiting list.");
}
}
private void addWaitingList() {
System.out.print("Waiting list count is " + waitingList.size() + " Enter Passenger Name:");
String name = sc.nextLine();
if (waitingList.isEmpty()) {
waitingList.add(name);
System.out.println("Added into waiting list successfully!");
}
}
public void cancel() {
System.out.print("Enter Passenger Name:");
String name = sc.nextLine();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 4; j++) {
if (name.equalsIgnoreCase(sheats[i][j])) {
sheats[i][j] = null;
if (!waitingList.isEmpty()) {
sheats[i][j] = waitingList.get(0);
waitingList.remove(0);
System.out.println("your ticket canceled successfully!");
break;
}
}
}
break;
}
}
public void quit() {
System.out.print("Thanks for using our application!");
System.exit(0);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.