Java Programming Question.

Q. A small airline has just purchased a computer for its new automated reservations system. You
have been asked to develop the new system. You are 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:
1. Please type 1 for First Class and
2. Please type 2 for Economy.
If the user types 1, your application should assign a seat in the first-class 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
is in the first-class or economy section of the plane.
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 elements 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 is 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.”

Java Code:

import javax.swing.JOptionPane;
public class que1ans {

static boolean seats[]={false,false,false,false,false,false,false,false,false,false};
String s= new String();
String temp = new String();

int a=0;
int b=0;

void firstClass()
{
for(int i=0; i<5; i++)
if(seats[i]==false)
{
seats[i]=true;
temp = “Seat Is Available n Your Boarding Pass :”+”nYour Seat Number => “+(i+1)+”nYour Class is => First”;
a++;
JOptionPane.showMessageDialog(null, temp);
break;
}
else if(a>=5 && b>=5)
{
temp=”Sorry No Seats Are Availablen Next flight leaves in 3 hours”;
JOptionPane.showMessageDialog(null, temp);
break;
}
else if(a>=5)
{

temp = “Sorry Seats are Not Available In This ClassnSeat May Be Available in Economy ClassnDo you Like To Go For Economy Class”;

s= JOptionPane.showInputDialog(temp+”nPress Y for Yes , N for No”);
if(s.equals(“n”) || s.equals(“N”))
{
temp=”Thanks For Using This System”;
JOptionPane.showMessageDialog(null, temp);
break;

}
else if(s.equals(“Y”) || s.equals(“y”))
{
economyClass();
break;
}
else
{ temp=”Please Enter Valid Choice “;
JOptionPane.showMessageDialog(null, temp);
break;
}



}





}

void economyClass()
{

for(int i=5; i<10; i++)
if(seats[i]==false)
{
seats[i]=true;
temp=”Seat Is AvailablennYour Boarding Pass is:nnYour Seat Number => “+(i+1)+”nYour Class is => Economy”;
JOptionPane.showMessageDialog(null, temp);
b++;
break;
}
else if(a>=5 && b>=5)
{
temp=”Sorry Seats Are Not Availablen Next flight leaves in 3 hours”;
JOptionPane.showMessageDialog(null, temp);
break;
}
else if(b>=5)
{
temp=” Sorry Seats are Not Available In This Class n Seat May Be Available in First Class n Do you Like To Go For First Class”;
s= JOptionPane.showInputDialog(temp+”Press Y for Yes , N for No”);
if(s.equals(“n”) || s.equals(“N”))
{
temp=”Thanks For Using This System”;
JOptionPane.showMessageDialog(null,
temp);
break;
}
else if(s.equals(“Y”) || s.equals(“y”))
{
firstClass();
break;
}
else
{
temp=”Please Enter Valid Choice “;
JOptionPane.showMessageDialog(null, temp);
break;
}
}

}




/**
* @param args
*/

public static void main(String[] args) {
// TODO Auto-generated method stub
int c;
que1ans app = new que1ans();
int x=0;
String temp2= new String();

String title=new String(“n Wel-Come To Automated Reservations System”);
try{
do
{
temp2=”Please type 1 for First ClassnPlease type 2 for EconomynPlease type 3 for seating chart of the planenPlease type 4 to exit”;
JOptionPane.showMessageDialog(null, temp2, title, 0);
c = Integer.parseInt(JOptionPane.showInputDialog(“Enter Your Choice..”));

switch(c)
{

case 1:
app.firstClass();
break;

case 2:
app.economyClass();
break;
case 3:
temp2=” First Class => 1-5 n Economy Class => 6-10 n False =>Seat Available n True => Seat Not Available”;
for(int y=0; y<10; y++)
temp2= temp2 + “n Seat No [“+(y+1)+”] =>” + que1ans.seats[y];
JOptionPane.showMessageDialog(null, temp2, title, 0);
break;
case 4:
x++;
break;

default:
temp2=”n Please Enter Valid Option”;
JOptionPane.showMessageDialog(null, temp2, title, 6);
}


}while(x==0);

}
catch(Exception e)
{
System.out.println(“Please Enter Valid Input”);
JOptionPane.showMessageDialog(null, new String(“Please Enter Valid Input And Restart The App”));
}


}

}

Comments

Popular posts from this blog

MATLAB code for Circular Convolution using Matrix method

Positive number pipe in angular 2+