Java Programming Question.
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
Post a Comment