Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class SeatReservation {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String seats[][] = new String[10][4];
- String choice;
- for(int i = 0; i < seats.length; i++){
- for(int x = 0; x < seats[0].length; x++){
- seats[i][x] = "*";
- }
- }
- boolean isNotNegative = true;
- while(isNotNegative){
- System.out.println("Bus Seat Reservation: ");
- System.out.println("\t\tCol 1 \t Col 2 \t Col 3 \t Col 4");
- //Printinggggg
- for(int z = 0; z < seats.length; z++){
- if((z + 1) == 10){
- System.out.print("Row " + (z + 1) + " |");
- }else{
- System.out.print("Row " + (z + 1) + " |");
- }
- for(int i = 0; i < seats[0].length; i++){
- System.out.print(" "+ seats[z][i] + "\t\t");
- }
- System.out.println("");
- }
- System.out.print("Enter row and column number to reserve separated by space (Enter a negative number to exit): ");
- choice = input.nextLine();
- //Change into array of strings
- String[] StrNumChoice = choice.split(" ");
- int intNumChoice[] = {0,0};
- //Make String into numbers
- for(int i = 0; i < StrNumChoice.length; i++){
- intNumChoice[i] = Integer.parseInt(StrNumChoice[i]);
- }
- //If negative, terminate the program
- if(intNumChoice[0] < 0){
- isNotNegative = false;
- System.out.println("Program Exit!");
- }else{
- //Add X/
- seats[intNumChoice[0] - 1][intNumChoice[1] - 1] = "X";
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment