Problem #1: (Airline Reservations System) A small airline has just purchased a c
ID: 3823616 • Letter: P
Question
Problem #1:
(Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system. You’ve been asked to develop the new system. You’re to write an application to assign seats on each flight of the airline’s only plane (capacity: 10 seats).Your application should display the following alternatives: Please type 1 for First Class and Please type 2 for Economy. If the user types 1, your application should assign a seat in the firstclass section (seats 1–5). If the user types 2, your application should assign a seat in the economy section (seats 6–10). Your application should then display a boarding pass indicating the person’s seat number and whether it’s in the first-class or economy section of the plane.Use a one-dimensional array of primitive type boolean to represent the seating chart of the plane. Initialize all the elements of the array to false to indicate that all the seats are empty. As each seat is assigned, set the corresponding element of the array to true to indicate that the seat is no longer available.Your application should never assign a seat that has already been assigned. When the economy section is full, your application should ask the person if it’s acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message "Next flight leaves in 3 hours." (10 points)
Problem #2:
Write an application that reads an English-language phrase and encodes it into Morse code. Look up on google the international Morse code table. (5 points)
Explanation / Answer
Hi,
Source code :
//Program for airline seat reservation
//import for taking input from user
import java.util.Scanner;
public class NewAirlinesReservation
{
//Array of seats
boolean[] flightSeats = new boolean[11];
Scanner input = new Scanner(System.in);
public void start()
{
while ( true )
{
bookSeat();
}
}
// Function for booking a seat in reservtion system
public void bookSeat()
{
//Asks user for his preffered class to travel
System.out.println("Choose Your preference : type '1' for First Class or '2' for Economy Class:");
int pessangerClass = input.nextInt();
if ( pessangerClass == 1 )
{
firstClassBooking();
}
else
{
economyClassBooking();
}
}
// Check and book for first class seating
public void firstClassBooking()
{
for ( int cnt = 1; cnt <= 5; cnt++ )
{
//check if seat is available to allocate to user booking.
if ( flightSeats[cnt] == false )
{
//book seat
flightSeats[cnt] = true;
System.out.printf("First Class Seat Booking: Seat# %d ", cnt);
break;
}
else if ( flightSeats[5] == true )
{
if ( flightSeats[10] == true)
{
//if both classes are fully booked
System.out.println("Apologies!! All seats are booked. Next flight is scheduled in '3' hours.");
}
else
{
// provide pessanger another available class option
System.out.println("Sorry,First Class bookings are over. Would you like to opt for Economy class ? select '1' for Yes and '2' for No");
int selection = input.nextInt();
if ( selection == 1 )
{
economyClassBooking();
start();
}
else
{
System.out.println("Next flight is scheduled in '3' hours.");
System.exit(0);
}
}
}
}
}
// Check and book for economy class seating
public void economyClassBooking() // assign an economy seat
{
for ( int cnt = 6; cnt <= 10; cnt++ )
{
if ( flightSeats[cnt] == false )
{
flightSeats[cnt] = true;
System.out.printf("economy class seat booking :# %d ", cnt);
break;
}
else if ( flightSeats[10] == true )
{
if ( flightSeats[5] == true)
{
System.out.println("Apologies!! All seats are booked. Next flight is scheduled in '3' hours.");
System.exit(0);
}
else
{
System.out.println("Sorry, Economy Class seat bookings are over. Would you like to opt for first Class seat? press '1' for Yes and '2' for No");
int selection = input.nextInt();
if ( selection == 1 )
{
firstClassBooking();
start();
}
else
{
System.out.println("Next flight is scheduled in 3 hours");
System.exit(0);
}
}
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.