import java.util.*;


public class exercise5 {

static Scanner console=new Scanner(System.in);

public static void main(String[] args) {
char[][] seats=new char[14][7]; //Declaration of variable seats (count starting 1)
// w/ 13 rows and 6 columns.
int row;
int col;
int ticket_type;
char vacant='*';
char smokingOrnot;
char choice;
boolean bol=false;

System.out.println("\tA B C D E F");

for (row=1;row for(col=1; col seats[row][col]=vacant; //Initialize all seats to be vacant.



for (row=1;row {
System.out.printf("ROW%2d ",row);
for (col = 1; col < seats[row].length; col++)
{
System.out.print(" "+ seats[row][col]); //Print the seats array.
}

System.out.println();
}



while(bol!=true){ //Flag-Controlled While Loops.
System.out.println("Ticket type(1 for First Class, 2 for EconomyClass):"
+"\n1.First Class\n2.Economy Class ");
System.out.print("Input: ");
ticket_type=console.nextInt();

if(ticket_type==1)
{


System.out.println("\t****First Class****");//First Class ticket
//type.
System.out.println("Row 1-2 ,Col 1-6");
System.out.print("Where do you want to seat(numbers only):");
System.out.print("Row?");
row=console.nextInt();
System.out.print("Col?");
col=console.nextInt();

if(seats[row][col]=='*'){
if(row<=2&&col<=6)
{
System.out.print("Thank You the seat is now reserved.");
seats[row][col]='X';//Register X to symbolize occupied seats.
System.out.println();
bol=true;
System.out.println("\tA B C D E F");
for (row=1;row {
System.out.printf("ROW%2d ",row);
for (col = 1; col < seats[row].length; col++)
{
System.out.print(" "+ seats[row][col]); //Print seats array.
}
System.out.println();
}

System.out.println("Do you want to reserve again?(Y/N)");

choice=console.next().charAt(0);
choice =Character.toUpperCase(choice);

if(choice=='Y'){
bol=false;}

else if(choice=='N'){
System.exit(0);}

}

}
else if(seats[row][col]=='X'){
System.out.println("SEAT ALREADY OCCUPIED "
+ "PLEASE CHOOSE A DIFFERENT SEAT.");
}

}//End brace of first class



else if (ticket_type == 2)
{
System.out.println("\t****Economy Class****");
System.out.println("Smoking or Non-smoking S/N ?");
smokingOrnot=console.next().charAt(0);
smokingOrnot =Character.toUpperCase(smokingOrnot);

if(smokingOrnot=='S')
{
System.out.println("\t****Smoking Section****");
System.out.println("Row 8-13 ,Col 1-6");
System.out.print("Where do you want to seat(numbers only):");
System.out.print("Row?");
row=console.nextInt();
System.out.print("Col?");
col=console.nextInt();

if(seats[row][col]=='*'){

if(row>=8&&row<=13&&col<=6)
{
System.out.print("Thank You the seat is now reserved.");
seats[row][col]='X';//Register X to symbolize occupied
System.out.println();//seats
bol=true;
System.out.println("\tA B C D E F");
for (row=1;row {
System.out.printf("ROW%2d ",row);
for (col = 1; col < seats[row].length; col++)
{
System.out.print(" "+ seats[row][col]); //Print seats array.
}
System.out.println();
}

System.out.println("Do you want to reserve again?(Y/N)");

choice=console.next().charAt(0);
choice =Character.toUpperCase(choice);

if(choice=='Y'){
bol=false;}

else if(choice=='N'){
System.exit(0);}
}
}
else if(seats[row][col]=='X'){
System.out.println("SEAT ALREADY OCCUPIED "
+ "PLEASE CHOOSE A DIFFERENT SEAT.");
}

}//End brace of Smoking Section.

else if(smokingOrnot=='N')
{
System.out.println("\t***Non-Smoking Section****");
System.out.println("Row 3-7 ,Col 1-6");
System.out.print("Where do you want to seat(numbers only):");
System.out.print("Row?");
row=console.nextInt();
System.out.print("Col?");
col=console.nextInt();

if(seats[row][col]=='*'){

if(row>=3&&row<=7&&col<=6)
{
System.out.print("Thank You the seat is now reserved.");
seats[row][col]='X';//Register X to symbolize occupied seats.
System.out.println();
bol=true;
System.out.println("\tA B C D E F");
for (row=1;row {
System.out.printf("ROW%2d ",row);
for (col = 1; col < seats[row].length; col++)
{
System.out.print(" "+ seats[row][col]); //Print seats array.
}
System.out.println();
}


System.out.println("Do you want to reserve again?(Y/N)");
choice=console.next().charAt(0);
choice =Character.toUpperCase(choice);

if(choice=='Y'){
bol=false;}

else if(choice=='N'){
System.exit(0);}

}
}

else if(seats[row][col]=='X'){
System.out.println("SEAT ALREADY OCCUPIED "
+ "PLEASE CHOOSE A DIFFERENT SEAT.");
}

}//End brace of Non-smoking section.

}//End brace of Economy Class


else{
System.out.println("INVALID INPUT! GOING BACK TO MENU.");
}

}//End brace of flag controlled loop.


}//End brace of main method.

}//End brace of public class.

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/u-hz5FOeI4s/12961