angeloeboy10

JAva

Jan 12th, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SeatReservation {
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.  
  9.         String seats[][] = new String[10][4];
  10.         String choice;
  11.  
  12.         for(int i = 0; i < seats.length; i++){
  13.  
  14.             for(int x = 0; x < seats[0].length; x++){
  15.                 seats[i][x] = "*";
  16.             }
  17.         }
  18.         boolean isNotNegative = true;
  19.  
  20.         while(isNotNegative){
  21.  
  22.             System.out.println("Bus Seat Reservation: ");
  23.             System.out.println("\t\tCol 1 \t Col 2 \t Col 3 \t Col 4");
  24.  
  25.             //Printinggggg
  26.             for(int z = 0; z < seats.length; z++){
  27.  
  28.                 if((z + 1) == 10){
  29.                     System.out.print("Row " + (z + 1) + " |");
  30.                 }else{
  31.                     System.out.print("Row " + (z + 1) + "  |");
  32.                 }
  33.  
  34.                 for(int i = 0; i < seats[0].length; i++){
  35.                     System.out.print("  "+ seats[z][i] + "\t\t");
  36.                 }
  37.  
  38.                 System.out.println("");
  39.  
  40.             }
  41.  
  42.             System.out.print("Enter row and column number to reserve separated by space (Enter a negative number to exit): ");
  43.             choice = input.nextLine();
  44.  
  45.             //Change into array of strings
  46.             String[] StrNumChoice = choice.split(" ");
  47.             int intNumChoice[] = {0,0};
  48.  
  49.  
  50.             //Make String into numbers
  51.             for(int i = 0; i < StrNumChoice.length; i++){
  52.                 intNumChoice[i] = Integer.parseInt(StrNumChoice[i]);
  53.             }
  54.  
  55.             //If negative, terminate the program
  56.             if(intNumChoice[0] < 0){
  57.                 isNotNegative = false;
  58.                 System.out.println("Program Exit!");
  59.             }else{
  60.  
  61.                 //Add X/
  62.                 seats[intNumChoice[0] - 1][intNumChoice[1] - 1] = "X";
  63.             }
  64.  
  65.  
  66.         }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.     }
  75. }
  76.  
Add Comment
Please, Sign In to add comment