SHARE
TWEET

Seat Reservation - Clemente

a guest Nov 12th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class SeatReservationEubie {
  4.    
  5.     public static void main(String[] args)
  6.     {
  7.         Scanner userInput = new Scanner(System.in);
  8.         char[][] seatReserved = new char[10][4];
  9.         String seatNum = "";
  10.         for(int x = 0; x < seatReserved.length; x++)
  11.         {
  12.             for(int y = 0; y < seatReserved[0].length; y++)
  13.             {
  14.                 seatReserved[x][y] = '*';
  15.             }
  16.         }
  17.         while(true)
  18.         {
  19.             System.out.println("Bus Seat Reservation:");
  20.             String[] parse;
  21.             System.out.println("\n\tCol 1\tCol 2\tCol 3\tCol 4\n");
  22.             for(int x = 0; x < seatReserved.length; x++)
  23.             {
  24.                 System.out.print("Row " + (x + 1) + " |");
  25.                 for(int y = 0; y < seatReserved[0].length; y++)
  26.                 {
  27.                     System.out.print(seatReserved[x][y]+ "\t");
  28.                 }
  29.                 System.out.println();
  30.             }
  31.             while(true) {
  32.                 System.out.print("\nEnter row and column number to reserve separated by space (Enter a negative number to exit): ");
  33.                 seatNum = userInput.nextLine();
  34.                 parse = seatNum.split(" ");
  35.            
  36.                 if(parse.length > 2 || parse.length < 2)
  37.                 {
  38.                     System.out.println("\nYou just entered 3 spaces! or 3 input or Must be 2 inputs!");
  39.                 }
  40.                 else if(Integer.parseInt(parse[0]) >= seatReserved.length)
  41.                 {
  42.                     System.out.println("The Row must not above " + seatReserved.length);
  43.                 }
  44.                 else if(Integer.parseInt(parse[1]) >= seatReserved[0].length)
  45.                 {
  46.                     System.out.println("The Row must not above " + seatReserved[0].length);
  47.                 }
  48.                 else break;
  49.             }
  50.            
  51.             if(Integer.parseInt(parse[0]) < 0 || Integer.parseInt(parse[1]) < 0)
  52.             {
  53.                 System.out.println("Negative Value is not allowed!\n");
  54.                 break;
  55.             }
  56.             if(seatReserved[Integer.parseInt(parse[0])][Integer.parseInt(parse[1])] == 'x') {
  57.                 System.out.println("That slot is already taken!\n");
  58.             }
  59.             else seatReserved[Integer.parseInt(parse[0])][Integer.parseInt(parse[1])] = 'x';
  60.         }
  61.     }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top