SlideShare a Scribd company logo
1 of 14
Download to read offline
public class Passenger {
public static enum Section {
First, Economy
}
private String name;
private Section section;
private String confirmationCode;
/**
* Constructor
*
* @param name
* @param section
* @param confirmationCode
*/
public Passenger(String name, Section section, String confirmationCode) {
this.name = name;
this.section = section;
this.confirmationCode = confirmationCode;
}
/**
* Copy Constructor that produces a deep copy of the argument
*
* @param
*/
public Passenger(Passenger p) {
this.name = p.name;
this.section = p.section;
this.confirmationCode = p.confirmationCode;
}
/**
* Returns a string with confirmation code
*/
public static String generateCode() {
String alphabet = "abcdefghijklmnopqrstuvwxyz";
String[] letters = new String[6];
String code = "";
for (int i = 0; i < 6; i++) {
letters[i] = "" + alphabet.charAt((int) Math.floor(Math.random() * 26));
code += letters[i];
}
return code.toUpperCase();
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the section
*/
public Section getSection() {
return section;
}
/**
* @param section the section to set
*/
public void setSection(Section section) {
this.section = section;
}
/**
* @return the confirmationCode
*/
public String getConfirmationCode() {
return confirmationCode;
}
/**
* @param confirmationCode the confirmationCode to set
*/
public void setConfirmationCode(String confirmationCode) {
this.confirmationCode = confirmationCode;
}
@Override
public String toString() {
return " Passenger name: " + getName() +
" Class: " + getSection() +
" Confirmation Code: " + getConfirmationCode();
}
}
import java.util.Scanner;
public class Manifest {
public static void printBP(Passenger p) {
System.out.print(String.format(" %30s", " ").replaceAll(" ", "-"));
System.out.print(p);
System.out.print(String.format(" %30s", " ").replaceAll(" ", "-"));
}
public static void main(String[] args) {
final int FIRST_CAPACITY = 2;
final int ECO_CAPACITY = 4;
// Scanner to get user input
Scanner in = new Scanner(System.in);
// Create passenger array
Passenger[] pList = new Passenger[6];
int reservationCount = 0;
// Variables to track whether a section is full
int firstSeats = 0;
int ecoSeats = 0;
char ch = ' ';
do {
// Get pax name
System.out.print("Enter the passenger's full name: ");
String name = in.nextLine();
// Get section
int section = -1;
while (true) {
System.out.println("Select a section 0-First, 1-Economy: ");
section = in.nextInt();
// Check if selected section is full
if (section == 0) {
if (firstSeats == FIRST_CAPACITY) {
System.out.println("First class seats are full. Do you wan to reserve a seat in the
economy section[Y/N]: ");
char reserve = in.next().charAt(0);
//If user does not want to make the reservation
//finish booking without a reservation
if(Character.toUpperCase(reserve) == 'N')
break;
section = 1; //Change section to economy if user selects Y
ecoSeats += 1;
} else
firstSeats += 1;
} else if (section == 1) {
if (ecoSeats == ECO_CAPACITY) {
System.out.println("Economy class seats are full. Do you wan to reserve a seat in
the first section[Y/N]: ");
char reserve = in.next().charAt(0);
//If user does not want to make the reservation
//finish booking without a reservation
if(Character.toUpperCase(reserve) == 'N')
break;
section = 0; //Change section to economy if user selects Y
firstSeats += 1;
} else
ecoSeats += 1;
} else {
System.out.println("Invalid section. Please try again.");
continue;
}
//Make reservation
// Generate code
String code = Passenger.generateCode();
pList[reservationCount] = new Passenger(name, Passenger.Section.values()[section],
code);
printBP(pList[reservationCount]); //Print BP
reservationCount += 1;
break;
}
if(reservationCount == 6)
break;
else {
System.out.println(" Do you want to make another reservation[Y/N]: ");
ch = in.next().charAt(0);
}
//Clear keyboard buffer
in.nextLine();
} while (Character.toUpperCase(ch) == 'Y');
// Close scanner
in.close();
//Print manifest
System.out.println("MANIFEST");
System.out.printf(" %-20s %-20s %-10s", "Confirmation Code", "Passenger",
"Class");
System.out.print(String.format(" %52s", " ").replaceAll(" ", "-"));
for (Passenger pax : pList) {
if(pax != null)
System.out.printf(" %-20s %-20s %-10s", pax.getConfirmationCode(),
pax.getName(), pax.getSection());
}
}
}
SAMPLE OUTPUT:
Enter the passenger's full name: Passenger 1
Select a section 0-First, 1-Economy:
1
------------------------------
Passenger name: Passenger 1
Class: Economy
Confirmation Code: UZIBJN
------------------------------
Do you want to make another reservation[Y/N]:
y
Enter the passenger's full name: Passenger 2
Select a section 0-First, 1-Economy:
0
------------------------------
Passenger name: Passenger 2
Class: First
Confirmation Code: IRHYRQ
------------------------------
Do you want to make another reservation[Y/N]:
y
Enter the passenger's full name: Passenger 3
Select a section 0-First, 1-Economy:
0
------------------------------
Passenger name: Passenger 3
Class: First
Confirmation Code: AAGOYD
------------------------------
Do you want to make another reservation[Y/N]:
y
Enter the passenger's full name: Passenger 4
Select a section 0-First, 1-Economy:
0
First class seats are full. Do you wan to reserve a seat in the economy section[Y/N]:
n
Do you want to make another reservation[Y/N]:
y
Enter the passenger's full name: Passenger 5
Select a section 0-First, 1-Economy:
0
First class seats are full. Do you wan to reserve a seat in the economy section[Y/N]:
y
------------------------------
Passenger name: Passenger 5
Class: Economy
Confirmation Code: DFFWQN
------------------------------
Do you want to make another reservation[Y/N]:
n
MANIFEST
Confirmation Code Passenger Class
----------------------------------------------------
UZIBJN Passenger 1 Economy
IRHYRQ Passenger 2 First
AAGOYD Passenger 3 First
DFFWQN Passenger 5 Economy
Solution
public class Passenger {
public static enum Section {
First, Economy
}
private String name;
private Section section;
private String confirmationCode;
/**
* Constructor
*
* @param name
* @param section
* @param confirmationCode
*/
public Passenger(String name, Section section, String confirmationCode) {
this.name = name;
this.section = section;
this.confirmationCode = confirmationCode;
}
/**
* Copy Constructor that produces a deep copy of the argument
*
* @param
*/
public Passenger(Passenger p) {
this.name = p.name;
this.section = p.section;
this.confirmationCode = p.confirmationCode;
}
/**
* Returns a string with confirmation code
*/
public static String generateCode() {
String alphabet = "abcdefghijklmnopqrstuvwxyz";
String[] letters = new String[6];
String code = "";
for (int i = 0; i < 6; i++) {
letters[i] = "" + alphabet.charAt((int) Math.floor(Math.random() * 26));
code += letters[i];
}
return code.toUpperCase();
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the section
*/
public Section getSection() {
return section;
}
/**
* @param section the section to set
*/
public void setSection(Section section) {
this.section = section;
}
/**
* @return the confirmationCode
*/
public String getConfirmationCode() {
return confirmationCode;
}
/**
* @param confirmationCode the confirmationCode to set
*/
public void setConfirmationCode(String confirmationCode) {
this.confirmationCode = confirmationCode;
}
@Override
public String toString() {
return " Passenger name: " + getName() +
" Class: " + getSection() +
" Confirmation Code: " + getConfirmationCode();
}
}
import java.util.Scanner;
public class Manifest {
public static void printBP(Passenger p) {
System.out.print(String.format(" %30s", " ").replaceAll(" ", "-"));
System.out.print(p);
System.out.print(String.format(" %30s", " ").replaceAll(" ", "-"));
}
public static void main(String[] args) {
final int FIRST_CAPACITY = 2;
final int ECO_CAPACITY = 4;
// Scanner to get user input
Scanner in = new Scanner(System.in);
// Create passenger array
Passenger[] pList = new Passenger[6];
int reservationCount = 0;
// Variables to track whether a section is full
int firstSeats = 0;
int ecoSeats = 0;
char ch = ' ';
do {
// Get pax name
System.out.print("Enter the passenger's full name: ");
String name = in.nextLine();
// Get section
int section = -1;
while (true) {
System.out.println("Select a section 0-First, 1-Economy: ");
section = in.nextInt();
// Check if selected section is full
if (section == 0) {
if (firstSeats == FIRST_CAPACITY) {
System.out.println("First class seats are full. Do you wan to reserve a seat in the
economy section[Y/N]: ");
char reserve = in.next().charAt(0);
//If user does not want to make the reservation
//finish booking without a reservation
if(Character.toUpperCase(reserve) == 'N')
break;
section = 1; //Change section to economy if user selects Y
ecoSeats += 1;
} else
firstSeats += 1;
} else if (section == 1) {
if (ecoSeats == ECO_CAPACITY) {
System.out.println("Economy class seats are full. Do you wan to reserve a seat in
the first section[Y/N]: ");
char reserve = in.next().charAt(0);
//If user does not want to make the reservation
//finish booking without a reservation
if(Character.toUpperCase(reserve) == 'N')
break;
section = 0; //Change section to economy if user selects Y
firstSeats += 1;
} else
ecoSeats += 1;
} else {
System.out.println("Invalid section. Please try again.");
continue;
}
//Make reservation
// Generate code
String code = Passenger.generateCode();
pList[reservationCount] = new Passenger(name, Passenger.Section.values()[section],
code);
printBP(pList[reservationCount]); //Print BP
reservationCount += 1;
break;
}
if(reservationCount == 6)
break;
else {
System.out.println(" Do you want to make another reservation[Y/N]: ");
ch = in.next().charAt(0);
}
//Clear keyboard buffer
in.nextLine();
} while (Character.toUpperCase(ch) == 'Y');
// Close scanner
in.close();
//Print manifest
System.out.println("MANIFEST");
System.out.printf(" %-20s %-20s %-10s", "Confirmation Code", "Passenger",
"Class");
System.out.print(String.format(" %52s", " ").replaceAll(" ", "-"));
for (Passenger pax : pList) {
if(pax != null)
System.out.printf(" %-20s %-20s %-10s", pax.getConfirmationCode(),
pax.getName(), pax.getSection());
}
}
}
SAMPLE OUTPUT:
Enter the passenger's full name: Passenger 1
Select a section 0-First, 1-Economy:
1
------------------------------
Passenger name: Passenger 1
Class: Economy
Confirmation Code: UZIBJN
------------------------------
Do you want to make another reservation[Y/N]:
y
Enter the passenger's full name: Passenger 2
Select a section 0-First, 1-Economy:
0
------------------------------
Passenger name: Passenger 2
Class: First
Confirmation Code: IRHYRQ
------------------------------
Do you want to make another reservation[Y/N]:
y
Enter the passenger's full name: Passenger 3
Select a section 0-First, 1-Economy:
0
------------------------------
Passenger name: Passenger 3
Class: First
Confirmation Code: AAGOYD
------------------------------
Do you want to make another reservation[Y/N]:
y
Enter the passenger's full name: Passenger 4
Select a section 0-First, 1-Economy:
0
First class seats are full. Do you wan to reserve a seat in the economy section[Y/N]:
n
Do you want to make another reservation[Y/N]:
y
Enter the passenger's full name: Passenger 5
Select a section 0-First, 1-Economy:
0
First class seats are full. Do you wan to reserve a seat in the economy section[Y/N]:
y
------------------------------
Passenger name: Passenger 5
Class: Economy
Confirmation Code: DFFWQN
------------------------------
Do you want to make another reservation[Y/N]:
n
MANIFEST
Confirmation Code Passenger Class
----------------------------------------------------
UZIBJN Passenger 1 Economy
IRHYRQ Passenger 2 First
AAGOYD Passenger 3 First
DFFWQN Passenger 5 Economy

More Related Content

Similar to public class Passenger {    public static enum Section {        .pdf

Modify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfModify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfhullibergerr25980
 
In this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfIn this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfivylinvaydak64229
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfSANDEEPARIHANT
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docxmayank272369
 
I want to write this program in java.Write a simple airline ticket.pdf
I want to write this program in java.Write a simple airline ticket.pdfI want to write this program in java.Write a simple airline ticket.pdf
I want to write this program in java.Write a simple airline ticket.pdffeelinggift
 
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdfWrite the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdfarihantmum
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 
ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularD.pdf
ONLY EDIT  CapacityOptimizer.java, Simulator.java, and TriangularD.pdfONLY EDIT  CapacityOptimizer.java, Simulator.java, and TriangularD.pdf
ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularD.pdfvinodagrawal6699
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfforwardcom41
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfmohdjakirfb
 
Railway reservation system
Railway reservation systemRailway reservation system
Railway reservation systemPrashant Sharma
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfarmyshoes
 
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfData StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfrozakashif85
 

Similar to public class Passenger {    public static enum Section {        .pdf (15)

Modify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfModify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdf
 
In this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfIn this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdf
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx
 
I want to write this program in java.Write a simple airline ticket.pdf
I want to write this program in java.Write a simple airline ticket.pdfI want to write this program in java.Write a simple airline ticket.pdf
I want to write this program in java.Write a simple airline ticket.pdf
 
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdfWrite the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularD.pdf
ONLY EDIT  CapacityOptimizer.java, Simulator.java, and TriangularD.pdfONLY EDIT  CapacityOptimizer.java, Simulator.java, and TriangularD.pdf
ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularD.pdf
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdf
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
 
Railway reservation system
Railway reservation systemRailway reservation system
Railway reservation system
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdf
 
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfData StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
 

More from annesmkt

#include iostream #include fstream #include cstdlib #.pdf
 #include iostream #include fstream #include cstdlib #.pdf #include iostream #include fstream #include cstdlib #.pdf
#include iostream #include fstream #include cstdlib #.pdfannesmkt
 
six lone pairs (each F has three lone pairs) nit.pdf
                     six lone pairs (each F has three lone pairs)  nit.pdf                     six lone pairs (each F has three lone pairs)  nit.pdf
six lone pairs (each F has three lone pairs) nit.pdfannesmkt
 
silver cyanide i think coz HCN will be formed whi.pdf
                     silver cyanide i think coz HCN will be formed whi.pdf                     silver cyanide i think coz HCN will be formed whi.pdf
silver cyanide i think coz HCN will be formed whi.pdfannesmkt
 
Rh (Rhodium) is the answer. Solution .pdf
                     Rh (Rhodium) is the answer.  Solution        .pdf                     Rh (Rhodium) is the answer.  Solution        .pdf
Rh (Rhodium) is the answer. Solution .pdfannesmkt
 
please rate me.... .pdf
                     please rate me....                               .pdf                     please rate me....                               .pdf
please rate me.... .pdfannesmkt
 
No. The Mo is in +3 oxidation state and thus its .pdf
                     No. The Mo is in +3 oxidation state and thus its .pdf                     No. The Mo is in +3 oxidation state and thus its .pdf
No. The Mo is in +3 oxidation state and thus its .pdfannesmkt
 
In the automata theory, a nondeterministic finite.pdf
                     In the automata theory, a nondeterministic finite.pdf                     In the automata theory, a nondeterministic finite.pdf
In the automata theory, a nondeterministic finite.pdfannesmkt
 
Formaldehyde is an organic compound with the form.pdf
                     Formaldehyde is an organic compound with the form.pdf                     Formaldehyde is an organic compound with the form.pdf
Formaldehyde is an organic compound with the form.pdfannesmkt
 
d. the molecular orbital diagram for O2. .pdf
                     d. the molecular orbital diagram for O2.         .pdf                     d. the molecular orbital diagram for O2.         .pdf
d. the molecular orbital diagram for O2. .pdfannesmkt
 
Water molecules do not participate in acid base neutralization react.pdf
Water molecules do not participate in acid base neutralization react.pdfWater molecules do not participate in acid base neutralization react.pdf
Water molecules do not participate in acid base neutralization react.pdfannesmkt
 
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdf
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdfThe Mouse and the track ball uses pointing and dragging tasks.The ac.pdf
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdfannesmkt
 
The employer must estimate the total cost of the benefits promised a.pdf
The employer must estimate the total cost of the benefits promised a.pdfThe employer must estimate the total cost of the benefits promised a.pdf
The employer must estimate the total cost of the benefits promised a.pdfannesmkt
 
slopeSolutionslope.pdf
slopeSolutionslope.pdfslopeSolutionslope.pdf
slopeSolutionslope.pdfannesmkt
 
Plz send the clear image to me...so that i can solve it..Solutio.pdf
Plz send the clear image to me...so that i can solve it..Solutio.pdfPlz send the clear image to me...so that i can solve it..Solutio.pdf
Plz send the clear image to me...so that i can solve it..Solutio.pdfannesmkt
 
Prior to 2010, the United States banned HIV-positive individuals fro.pdf
Prior to 2010, the United States banned HIV-positive individuals fro.pdfPrior to 2010, the United States banned HIV-positive individuals fro.pdf
Prior to 2010, the United States banned HIV-positive individuals fro.pdfannesmkt
 
option (e) is correct.the feature that distinguishes fluorescence .pdf
option (e) is correct.the feature that distinguishes fluorescence .pdfoption (e) is correct.the feature that distinguishes fluorescence .pdf
option (e) is correct.the feature that distinguishes fluorescence .pdfannesmkt
 
NADP is the source of electrons for the light reactionsThe electro.pdf
NADP is the source of electrons for the light reactionsThe electro.pdfNADP is the source of electrons for the light reactionsThe electro.pdf
NADP is the source of electrons for the light reactionsThe electro.pdfannesmkt
 
import java.util.Scanner;public class Bottle {    private stat.pdf
import java.util.Scanner;public class Bottle {    private stat.pdfimport java.util.Scanner;public class Bottle {    private stat.pdf
import java.util.Scanner;public class Bottle {    private stat.pdfannesmkt
 
In previous year, 2 birthdays were on tuesday but this year theres.pdf
In previous year, 2 birthdays were on tuesday but this year theres.pdfIn previous year, 2 birthdays were on tuesday but this year theres.pdf
In previous year, 2 birthdays were on tuesday but this year theres.pdfannesmkt
 
Homology is defined as structures which are derived from a common an.pdf
Homology is defined as structures which are derived from a common an.pdfHomology is defined as structures which are derived from a common an.pdf
Homology is defined as structures which are derived from a common an.pdfannesmkt
 

More from annesmkt (20)

#include iostream #include fstream #include cstdlib #.pdf
 #include iostream #include fstream #include cstdlib #.pdf #include iostream #include fstream #include cstdlib #.pdf
#include iostream #include fstream #include cstdlib #.pdf
 
six lone pairs (each F has three lone pairs) nit.pdf
                     six lone pairs (each F has three lone pairs)  nit.pdf                     six lone pairs (each F has three lone pairs)  nit.pdf
six lone pairs (each F has three lone pairs) nit.pdf
 
silver cyanide i think coz HCN will be formed whi.pdf
                     silver cyanide i think coz HCN will be formed whi.pdf                     silver cyanide i think coz HCN will be formed whi.pdf
silver cyanide i think coz HCN will be formed whi.pdf
 
Rh (Rhodium) is the answer. Solution .pdf
                     Rh (Rhodium) is the answer.  Solution        .pdf                     Rh (Rhodium) is the answer.  Solution        .pdf
Rh (Rhodium) is the answer. Solution .pdf
 
please rate me.... .pdf
                     please rate me....                               .pdf                     please rate me....                               .pdf
please rate me.... .pdf
 
No. The Mo is in +3 oxidation state and thus its .pdf
                     No. The Mo is in +3 oxidation state and thus its .pdf                     No. The Mo is in +3 oxidation state and thus its .pdf
No. The Mo is in +3 oxidation state and thus its .pdf
 
In the automata theory, a nondeterministic finite.pdf
                     In the automata theory, a nondeterministic finite.pdf                     In the automata theory, a nondeterministic finite.pdf
In the automata theory, a nondeterministic finite.pdf
 
Formaldehyde is an organic compound with the form.pdf
                     Formaldehyde is an organic compound with the form.pdf                     Formaldehyde is an organic compound with the form.pdf
Formaldehyde is an organic compound with the form.pdf
 
d. the molecular orbital diagram for O2. .pdf
                     d. the molecular orbital diagram for O2.         .pdf                     d. the molecular orbital diagram for O2.         .pdf
d. the molecular orbital diagram for O2. .pdf
 
Water molecules do not participate in acid base neutralization react.pdf
Water molecules do not participate in acid base neutralization react.pdfWater molecules do not participate in acid base neutralization react.pdf
Water molecules do not participate in acid base neutralization react.pdf
 
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdf
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdfThe Mouse and the track ball uses pointing and dragging tasks.The ac.pdf
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdf
 
The employer must estimate the total cost of the benefits promised a.pdf
The employer must estimate the total cost of the benefits promised a.pdfThe employer must estimate the total cost of the benefits promised a.pdf
The employer must estimate the total cost of the benefits promised a.pdf
 
slopeSolutionslope.pdf
slopeSolutionslope.pdfslopeSolutionslope.pdf
slopeSolutionslope.pdf
 
Plz send the clear image to me...so that i can solve it..Solutio.pdf
Plz send the clear image to me...so that i can solve it..Solutio.pdfPlz send the clear image to me...so that i can solve it..Solutio.pdf
Plz send the clear image to me...so that i can solve it..Solutio.pdf
 
Prior to 2010, the United States banned HIV-positive individuals fro.pdf
Prior to 2010, the United States banned HIV-positive individuals fro.pdfPrior to 2010, the United States banned HIV-positive individuals fro.pdf
Prior to 2010, the United States banned HIV-positive individuals fro.pdf
 
option (e) is correct.the feature that distinguishes fluorescence .pdf
option (e) is correct.the feature that distinguishes fluorescence .pdfoption (e) is correct.the feature that distinguishes fluorescence .pdf
option (e) is correct.the feature that distinguishes fluorescence .pdf
 
NADP is the source of electrons for the light reactionsThe electro.pdf
NADP is the source of electrons for the light reactionsThe electro.pdfNADP is the source of electrons for the light reactionsThe electro.pdf
NADP is the source of electrons for the light reactionsThe electro.pdf
 
import java.util.Scanner;public class Bottle {    private stat.pdf
import java.util.Scanner;public class Bottle {    private stat.pdfimport java.util.Scanner;public class Bottle {    private stat.pdf
import java.util.Scanner;public class Bottle {    private stat.pdf
 
In previous year, 2 birthdays were on tuesday but this year theres.pdf
In previous year, 2 birthdays were on tuesday but this year theres.pdfIn previous year, 2 birthdays were on tuesday but this year theres.pdf
In previous year, 2 birthdays were on tuesday but this year theres.pdf
 
Homology is defined as structures which are derived from a common an.pdf
Homology is defined as structures which are derived from a common an.pdfHomology is defined as structures which are derived from a common an.pdf
Homology is defined as structures which are derived from a common an.pdf
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

public class Passenger {    public static enum Section {        .pdf

  • 1. public class Passenger { public static enum Section { First, Economy } private String name; private Section section; private String confirmationCode; /** * Constructor * * @param name * @param section * @param confirmationCode */ public Passenger(String name, Section section, String confirmationCode) { this.name = name; this.section = section; this.confirmationCode = confirmationCode; } /** * Copy Constructor that produces a deep copy of the argument * * @param */ public Passenger(Passenger p) { this.name = p.name; this.section = p.section; this.confirmationCode = p.confirmationCode; } /** * Returns a string with confirmation code */ public static String generateCode() { String alphabet = "abcdefghijklmnopqrstuvwxyz";
  • 2. String[] letters = new String[6]; String code = ""; for (int i = 0; i < 6; i++) { letters[i] = "" + alphabet.charAt((int) Math.floor(Math.random() * 26)); code += letters[i]; } return code.toUpperCase(); } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; } /** * @return the section */ public Section getSection() { return section; } /** * @param section the section to set */ public void setSection(Section section) { this.section = section; } /** * @return the confirmationCode */ public String getConfirmationCode() {
  • 3. return confirmationCode; } /** * @param confirmationCode the confirmationCode to set */ public void setConfirmationCode(String confirmationCode) { this.confirmationCode = confirmationCode; } @Override public String toString() { return " Passenger name: " + getName() + " Class: " + getSection() + " Confirmation Code: " + getConfirmationCode(); } } import java.util.Scanner; public class Manifest { public static void printBP(Passenger p) { System.out.print(String.format(" %30s", " ").replaceAll(" ", "-")); System.out.print(p); System.out.print(String.format(" %30s", " ").replaceAll(" ", "-")); } public static void main(String[] args) { final int FIRST_CAPACITY = 2; final int ECO_CAPACITY = 4; // Scanner to get user input Scanner in = new Scanner(System.in); // Create passenger array Passenger[] pList = new Passenger[6]; int reservationCount = 0; // Variables to track whether a section is full int firstSeats = 0; int ecoSeats = 0; char ch = ' ';
  • 4. do { // Get pax name System.out.print("Enter the passenger's full name: "); String name = in.nextLine(); // Get section int section = -1; while (true) { System.out.println("Select a section 0-First, 1-Economy: "); section = in.nextInt(); // Check if selected section is full if (section == 0) { if (firstSeats == FIRST_CAPACITY) { System.out.println("First class seats are full. Do you wan to reserve a seat in the economy section[Y/N]: "); char reserve = in.next().charAt(0); //If user does not want to make the reservation //finish booking without a reservation if(Character.toUpperCase(reserve) == 'N') break; section = 1; //Change section to economy if user selects Y ecoSeats += 1; } else firstSeats += 1; } else if (section == 1) { if (ecoSeats == ECO_CAPACITY) { System.out.println("Economy class seats are full. Do you wan to reserve a seat in the first section[Y/N]: "); char reserve = in.next().charAt(0); //If user does not want to make the reservation //finish booking without a reservation if(Character.toUpperCase(reserve) == 'N') break;
  • 5. section = 0; //Change section to economy if user selects Y firstSeats += 1; } else ecoSeats += 1; } else { System.out.println("Invalid section. Please try again."); continue; } //Make reservation // Generate code String code = Passenger.generateCode(); pList[reservationCount] = new Passenger(name, Passenger.Section.values()[section], code); printBP(pList[reservationCount]); //Print BP reservationCount += 1; break; } if(reservationCount == 6) break; else { System.out.println(" Do you want to make another reservation[Y/N]: "); ch = in.next().charAt(0); } //Clear keyboard buffer in.nextLine(); } while (Character.toUpperCase(ch) == 'Y'); // Close scanner in.close(); //Print manifest System.out.println("MANIFEST"); System.out.printf(" %-20s %-20s %-10s", "Confirmation Code", "Passenger", "Class"); System.out.print(String.format(" %52s", " ").replaceAll(" ", "-"));
  • 6. for (Passenger pax : pList) { if(pax != null) System.out.printf(" %-20s %-20s %-10s", pax.getConfirmationCode(), pax.getName(), pax.getSection()); } } } SAMPLE OUTPUT: Enter the passenger's full name: Passenger 1 Select a section 0-First, 1-Economy: 1 ------------------------------ Passenger name: Passenger 1 Class: Economy Confirmation Code: UZIBJN ------------------------------ Do you want to make another reservation[Y/N]: y Enter the passenger's full name: Passenger 2 Select a section 0-First, 1-Economy: 0 ------------------------------ Passenger name: Passenger 2 Class: First Confirmation Code: IRHYRQ ------------------------------ Do you want to make another reservation[Y/N]: y Enter the passenger's full name: Passenger 3 Select a section 0-First, 1-Economy: 0 ------------------------------ Passenger name: Passenger 3 Class: First Confirmation Code: AAGOYD ------------------------------
  • 7. Do you want to make another reservation[Y/N]: y Enter the passenger's full name: Passenger 4 Select a section 0-First, 1-Economy: 0 First class seats are full. Do you wan to reserve a seat in the economy section[Y/N]: n Do you want to make another reservation[Y/N]: y Enter the passenger's full name: Passenger 5 Select a section 0-First, 1-Economy: 0 First class seats are full. Do you wan to reserve a seat in the economy section[Y/N]: y ------------------------------ Passenger name: Passenger 5 Class: Economy Confirmation Code: DFFWQN ------------------------------ Do you want to make another reservation[Y/N]: n MANIFEST Confirmation Code Passenger Class ---------------------------------------------------- UZIBJN Passenger 1 Economy IRHYRQ Passenger 2 First AAGOYD Passenger 3 First DFFWQN Passenger 5 Economy Solution public class Passenger { public static enum Section { First, Economy }
  • 8. private String name; private Section section; private String confirmationCode; /** * Constructor * * @param name * @param section * @param confirmationCode */ public Passenger(String name, Section section, String confirmationCode) { this.name = name; this.section = section; this.confirmationCode = confirmationCode; } /** * Copy Constructor that produces a deep copy of the argument * * @param */ public Passenger(Passenger p) { this.name = p.name; this.section = p.section; this.confirmationCode = p.confirmationCode; } /** * Returns a string with confirmation code */ public static String generateCode() { String alphabet = "abcdefghijklmnopqrstuvwxyz"; String[] letters = new String[6]; String code = ""; for (int i = 0; i < 6; i++) { letters[i] = "" + alphabet.charAt((int) Math.floor(Math.random() * 26)); code += letters[i]; }
  • 9. return code.toUpperCase(); } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; } /** * @return the section */ public Section getSection() { return section; } /** * @param section the section to set */ public void setSection(Section section) { this.section = section; } /** * @return the confirmationCode */ public String getConfirmationCode() { return confirmationCode; } /** * @param confirmationCode the confirmationCode to set */ public void setConfirmationCode(String confirmationCode) {
  • 10. this.confirmationCode = confirmationCode; } @Override public String toString() { return " Passenger name: " + getName() + " Class: " + getSection() + " Confirmation Code: " + getConfirmationCode(); } } import java.util.Scanner; public class Manifest { public static void printBP(Passenger p) { System.out.print(String.format(" %30s", " ").replaceAll(" ", "-")); System.out.print(p); System.out.print(String.format(" %30s", " ").replaceAll(" ", "-")); } public static void main(String[] args) { final int FIRST_CAPACITY = 2; final int ECO_CAPACITY = 4; // Scanner to get user input Scanner in = new Scanner(System.in); // Create passenger array Passenger[] pList = new Passenger[6]; int reservationCount = 0; // Variables to track whether a section is full int firstSeats = 0; int ecoSeats = 0; char ch = ' '; do { // Get pax name System.out.print("Enter the passenger's full name: "); String name = in.nextLine(); // Get section int section = -1;
  • 11. while (true) { System.out.println("Select a section 0-First, 1-Economy: "); section = in.nextInt(); // Check if selected section is full if (section == 0) { if (firstSeats == FIRST_CAPACITY) { System.out.println("First class seats are full. Do you wan to reserve a seat in the economy section[Y/N]: "); char reserve = in.next().charAt(0); //If user does not want to make the reservation //finish booking without a reservation if(Character.toUpperCase(reserve) == 'N') break; section = 1; //Change section to economy if user selects Y ecoSeats += 1; } else firstSeats += 1; } else if (section == 1) { if (ecoSeats == ECO_CAPACITY) { System.out.println("Economy class seats are full. Do you wan to reserve a seat in the first section[Y/N]: "); char reserve = in.next().charAt(0); //If user does not want to make the reservation //finish booking without a reservation if(Character.toUpperCase(reserve) == 'N') break; section = 0; //Change section to economy if user selects Y firstSeats += 1; } else ecoSeats += 1; } else { System.out.println("Invalid section. Please try again.");
  • 12. continue; } //Make reservation // Generate code String code = Passenger.generateCode(); pList[reservationCount] = new Passenger(name, Passenger.Section.values()[section], code); printBP(pList[reservationCount]); //Print BP reservationCount += 1; break; } if(reservationCount == 6) break; else { System.out.println(" Do you want to make another reservation[Y/N]: "); ch = in.next().charAt(0); } //Clear keyboard buffer in.nextLine(); } while (Character.toUpperCase(ch) == 'Y'); // Close scanner in.close(); //Print manifest System.out.println("MANIFEST"); System.out.printf(" %-20s %-20s %-10s", "Confirmation Code", "Passenger", "Class"); System.out.print(String.format(" %52s", " ").replaceAll(" ", "-")); for (Passenger pax : pList) { if(pax != null) System.out.printf(" %-20s %-20s %-10s", pax.getConfirmationCode(), pax.getName(), pax.getSection()); } }
  • 13. } SAMPLE OUTPUT: Enter the passenger's full name: Passenger 1 Select a section 0-First, 1-Economy: 1 ------------------------------ Passenger name: Passenger 1 Class: Economy Confirmation Code: UZIBJN ------------------------------ Do you want to make another reservation[Y/N]: y Enter the passenger's full name: Passenger 2 Select a section 0-First, 1-Economy: 0 ------------------------------ Passenger name: Passenger 2 Class: First Confirmation Code: IRHYRQ ------------------------------ Do you want to make another reservation[Y/N]: y Enter the passenger's full name: Passenger 3 Select a section 0-First, 1-Economy: 0 ------------------------------ Passenger name: Passenger 3 Class: First Confirmation Code: AAGOYD ------------------------------ Do you want to make another reservation[Y/N]: y Enter the passenger's full name: Passenger 4 Select a section 0-First, 1-Economy: 0 First class seats are full. Do you wan to reserve a seat in the economy section[Y/N]:
  • 14. n Do you want to make another reservation[Y/N]: y Enter the passenger's full name: Passenger 5 Select a section 0-First, 1-Economy: 0 First class seats are full. Do you wan to reserve a seat in the economy section[Y/N]: y ------------------------------ Passenger name: Passenger 5 Class: Economy Confirmation Code: DFFWQN ------------------------------ Do you want to make another reservation[Y/N]: n MANIFEST Confirmation Code Passenger Class ---------------------------------------------------- UZIBJN Passenger 1 Economy IRHYRQ Passenger 2 First AAGOYD Passenger 3 First DFFWQN Passenger 5 Economy