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

I\'m working on a coding assignment but i need to make two changes that i don\'t

ID: 3686121 • Letter: I

Question

I'm working on a coding assignment but i need to make two changes that i don't know how to.

1. Let the user enter a letter (ie. A, B or C) for the column instead of a number.
2. If you see sample output, if a user chooses a specific seat, a 0 is put in that place, however i want an XX to be put in that place.

Please guide me.


import java.util.*;
public class Theater
{
static Scanner in = new Scanner(System.in);
static int[][] seatingChart;

public static void main(String[] args)
{
seatingChart = new int [][]
{
{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
{ 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
{ 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
{ 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
{ 20, 20, 30, 30, 40, 40, 30, 30, 20, 20 },
{ 20, 30, 30, 40, 50, 50, 40, 30, 30, 20 },
{ 30, 40, 50, 50, 50, 50, 50, 50, 40, 30 },
};

System.out.println(" SEATS");
System.out.println();
System.out.println(" A B C D E F G H I J");
System.out.println();
printSeats(seatingChart);
System.out.println();
System.out.println("The above is a birds eye view of all the seating available at Corpus Christi Theatre for the Arts. Row 1 is ");
System.out.println("closest to the stage while row 9 represents the back of the theatre. You can either choose a seat by entering ");
System.out.println("and seat letter, or you can choose a seat by entering a price.");


char response = 'Y';
while ((response == 'Y') || (response == 'y'))
{
System.out.print("Enter 1 to choose by seat or 2 to choose by price:");
int choice = in.nextInt();
switch (choice)
{
case 1:
{ sellSeatByNumber(seatingChart);
break; }
case 2:
{ sellSeatByPrice(seatingChart);
break; }
default:
{ System.out.println("This is not a valid number, please enter either 1 or 2: "); }
}
System.out.print("Would you like to reserve another seat (Y/N)?: ");
response = in.next().charAt(0);
}
System.out.print("Thank you, come again!");
}

public static void printSeats(int seatingChart[][])
{
   int row = 9;
for(int i=0; i<seatingChart.length; i++)
{
System.out.print("Row "+ row+ " ");

for(int j=0; j<seatingChart[i].length; j++)
{
if (j>0)
System.out.print(" ");
System.out.print(seatingChart[i][j]);
//System.out.println();
}
row--;
System.out.println();
}
}

public static void sellSeatByPrice(int seatingChart[][])
{
   int row = 0;
   int column = 0;
     
System.out.print("Please enter a price for the seat you would like: ");
int price = in.nextInt();
// boolean found = false;
out: for (int i=0;i<9;i++)
for (int j=0;j<10;j++)
if (seatingChart[i][j]==price)
{ seatingChart[i][j]= 0 ; break out; } // Notice this change
printSeats(seatingChart);
}
public static void sellSeatByNumber(int seatingChart[][])
{
   String user;
   int col = 0;
System.out.println("Enter row: ");
int row = in.nextInt();
row = Math.abs(row-9);
System.out.print("Enter seat: ");
col = in.nextInt();
col -= 1;
if (seatingChart[row][col]!=0)
{
seatingChart[row][col] = 0;
printSeats(seatingChart);
System.out.println("Your seat has been reserved and reflected with a 0 on the chart now.");
}
else

{ System.out.println("That seat is already taken, please try again");


}
    }
}

Explanation / Answer

import java.util.*;
public class Theater
{
    static Scanner in = new Scanner(System.in);
    static int[][] seatingChart;
    public static void main(String[] args)
    {
        seatingChart = new int [][]
        {
            { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
            { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
            { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
            { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
            { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
            { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
            { 20, 20, 30, 30, 40, 40, 30, 30, 20, 20 },
            { 20, 30, 30, 40, 50, 50, 40, 30, 30, 20 },
            { 30, 40, 50, 50, 50, 50, 50, 50, 40, 30 },
        };

        System.out.println(" SEATS");
        System.out.println();
        System.out.println(" A B C D E F G H I J");
        System.out.println();
        printSeats(seatingChart);
        System.out.println();
        System.out.println("The above is a birds eye view of all the seating available at Corpus Christi Theatre for the Arts. Row 1 is ");
   System.out.println("closest to the stage while row 9 represents the back of the theatre. You can either choose a seat by entering ");
        System.out.println("and seat letter, or you can choose a seat by entering a price.");


        char response = 'Y';
        while ((response == 'Y') || (response == 'y'))
        {
            System.out.print("Enter 1 to choose by seat or 2 to choose by price:");
            int choice = in.nextInt();
            switch (choice)
            {
                case 1:
                { sellSeatByNumber(seatingChart);
                    break; }
                    case 2:
                    { sellSeatByPrice(seatingChart);
                        break; }
                        default:
                        { System.out.println("This is not a valid number, please enter either 1 or 2: "); }
                    }
                    System.out.print("Would you like to reserve another seat (Y/N)?: ");
                    response = in.next().charAt(0);
                }
                System.out.print("Thank you, come again!");
            }
            public static void printSeats(int seatingChart[][])
            {
                int row = 9;
                for(int i=0; i<seatingChart.length; i++)
                {
                    System.out.print("Row "+ row+ " ");
                    for(int j=0; j<seatingChart[i].length; j++)
                    {
                        if (j>0)
                            System.out.print(" ");
                        if(seatingChart[i][j]==0)
                            System.out.print("XX");
                        else
                            System.out.print(seatingChart[i][j]);
//System.out.println();
                    }
                    row--;
                    System.out.println();
                }
            }
            public static void sellSeatByPrice(int seatingChart[][])
            {
                int row = 0;
                int column = 0;

                System.out.print("Please enter a price for the seat you would like: ");
                int price = in.nextInt();
// boolean found = false;
                out: for (int i=0;i<9;i++)
                for (int j=0;j<10;j++)
                    if (seatingChart[i][j]==price)
{ seatingChart[i][j]= 0 ; break out; } // Notice this change
printSeats(seatingChart);
}
public static void sellSeatByNumber(int seatingChart[][])
{
   String user;
   int col = 0;
   System.out.println("Enter row: ");
   int row = in.nextInt();
   row = Math.abs(row-9);
   System.out.print("Enter seat (Enter A or B or C): ");
   col_response = in.next().charAt(0);
   col = col_response - 'A';

   col -= 1;
   if (seatingChart[row][col]!=0)
   {
       seatingChart[row][col] = 0;
       printSeats(seatingChart);
       System.out.println("Your seat has been reserved and reflected with a XX on the chart now.");
   }
   else

       { System.out.println("That seat is already taken, please try again");


}
}
}