Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please modify the program below so that it is not case sensitive if the user ent

ID: 3682791 • Letter: P

Question

Please modify the program below so that it is not case sensitive if the user enters a lowercase letter when choosing a seat. It should accept both. Example : 1A or 1a . Also, I would like the program to print an error message if the user enter a seat number that is not valid such as 1E or 10A. It should print, "That is not a valid choice! Please enter a different seat."

import java.util.Scanner;

public class Seat {
static char[][] seats = new char[9][4];
static String[][] userNames = new String[9][4];

public static void main(String[] args) {
@SuppressWarnings("resource")
       Scanner read = new Scanner(System.in);
for (int i = 0; i < 9; ++i) {
for (int j = 0; j < 4; ++j) {
seats[i][j] = (char) (j + 'A');
}
}
  
printSeatChart();

while (!isFull()) {
boolean validSeat = false;
int row = -1, col = -1;
String seatNumber = null;
while (!validSeat) {
System.out.print("Enter seat number: ");
seatNumber = read.nextLine();
row = seatNumber.charAt(0) - '0' - 1;
col = seatNumber.charAt(1) - 'A';
if (seats[row][col] == 'X') {
System.out.format("Seat number: %s cannot be reserved. Please select a different seat. ",
seatNumber);
} else validSeat = true;
}
System.out.format("Would you like to reserve %s? Y/N: ", seatNumber);
char userChoice = read.nextLine().toLowerCase().charAt(0);
if (userChoice == 'y') {
System.out.print("Enter your name: ");
String userName = read.nextLine();
userNames[row][col] = userName;
seats[row][col] = 'X';
System.out.format("Reservation of seat number: %s to: %s was successful. ",
seatNumber, userName);
printSeatChart();
}
}

System.out.println("We are sorry, there are no more seats available.");
}

private static void printSeatChart() {
for (int i = 0; i < 9; ++i) {
System.out.format("%d %c %c %c %c ",
(i + 1), seats[i][0], seats[i][1], seats[i][2], seats[i][3]);
}
}

private static boolean isFull() {
for (int i = 0; i < 9; ++i) {
for (int j = 0; j < 4; ++j) {
if (seats[i][j] != 'X') return false;
}
}
return true;
}
}

Explanation / Answer

Please go through the bold lines of the program where changes are made

import java.util.Scanner;

public class Seat1 {
    static char[][] seats = new char[9][4];
    static String[][] userNames = new String[9][4];

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner read = new Scanner(System.in);
        for (int i = 0; i < 9; ++i) {
            for (int j = 0; j < 4; ++j) {
                seats[i][j] = (char) (j + 'A');
            }
        }
      
        printSeatChart();

        while (!isFull()) {
            boolean validSeat = false;
            int row = -1, col = -1;
            String seatNumber = null;
            String ro="";
            while (!validSeat) {
                System.out.print("Enter seat number: ");
                seatNumber = read.nextLine().toUpperCase(); //convert to upper case
                System.out.println(seatNumber);
                int length = seatNumber.length(); // find length of string
              
                if(length>2) {
                   ro = ro + seatNumber.charAt(0);
                   ro = ro + seatNumber.charAt(1);
                   row = Integer.parseInt(ro);
                   col = seatNumber.charAt(2) - 'A';
                   System.out.println(row);
                } else {
                    row = seatNumber.charAt(0) - '0' - 1;
                    col = seatNumber.charAt(1) - 'A';
                }
             
                if(row>=10 || col>3) {
                   System.out.println("That is not valid choice please enter different seat");
                  
                }else if (seats[row][col] == 'X') {
                    System.out.format("Seat number: %s cannot be reserved. Please select a different seat. ",
                            seatNumber);
                } else validSeat = true;
            }

            System.out.format("Would you like to reserve %s? Y/N: ", seatNumber);
            char userChoice = read.nextLine().toLowerCase().charAt(0);
            if (userChoice == 'y') {
                System.out.print("Enter your name: ");
                String userName = read.nextLine();
                userNames[row][col] = userName;
                seats[row][col] = 'X';
                System.out.format("Reservation of seat number: %s to: %s was successful. ",
                        seatNumber, userName);
                printSeatChart();
            }
        }

        System.out.println("We are sorry, there are no more seats available.");
    }

    private static void printSeatChart() {
        for (int i = 0; i < 9; ++i) {
            System.out.format("%d %c %c %c %c ",
                    (i + 1), seats[i][0], seats[i][1], seats[i][2], seats[i][3]);
        }
    }

    private static boolean isFull() {
        for (int i = 0; i < 9; ++i) {
            for (int j = 0; j < 4; ++j) {
                if (seats[i][j] != 'X') return false;
            }
        }
        return true;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote