Sunday 15 December 2013

Write a function for seat allocate and seat reserved.

public class SeatingPlan {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        boolean[][] seat = new boolean[10][20];
        char[] alphabets=new char[]{'A','B','C','D','E','F','G','H','I','J'};
        System.out.println("X = Seat occupied" + "\n\n" + "   <<--------- SCREEN ---------- >>");
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 20; j++) {
                String seating = (seat[i][j] == true) ? alphabets[i]+""+j+"   [X] " : alphabets[i]+""+j+ "   [0] ";
                System.out.print(seating);
            }
            System.out.println("");
        }
        System.out.println("Please select a seat for your self");
        BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
        String bookthisSeat=br1.readLine().toUpperCase();
        char a=bookthisSeat.charAt(0);
     
        int row=(int)a-65;
        int col= Integer.parseInt(bookthisSeat.substring(1,2));
        if (seat[row][col]==false)
        {
            seat[row][col]=true;
            System.out.println("Congrats!! your ticket is booked and seat is now reserved for you");
         
        }
        else
            System.out.println("sorry your ticket can not be booked this seat is already occupied.... Please fined another seat");
     
    }
}

No comments:

Post a Comment