Question: I CANNOT USE OBJECTS Hi so here is the problem my code only works have way as to what the specifications are. They are listed

I CANNOT USE OBJECTS

Hi so here is the problem my code only works have way as to what the specifications are. They are listed in the comments above each method

The method take reservation does not work as it should I need help with getting it a to function as asked I have highlited below my issues the bottom of the oage has a description of what the entire program does

If This part could work then it would at least pass

###################################################################

import java.io.*; import java.util.Scanner; import java.util.*; public class lab12 {

/************************************************************************************************************ * The following method is not for you to modify. * It is given to you because it is needed in the main * method. * It takes two integers, which represent a number of rows * and a number of seats per row * It generates and returns a 2D array of integers of size * row x seats, which contains integer prices for each * corresponding seat *********************************************************/ public static int[][] loadInfo(int row, int seats) { int[][] seatsPrices = new int[row][seats]; //assigns prices to each seat in row for (int i=0; i for (int j=0; j< seats; j++) { // return s a decimal to the nearest tenth times and (int) to make it a integer seatsPrices[i][j]=(int) Math.floor(Math.random() * 101); // if less than 30 prices are set to 30$ if (seatsPrices[i][j] < 30) seatsPrices[i][j]+=30; System.out.print(seatsPrices[i][j] + " "); } System.out.println(); } return seatsPrices; }

/************************************************************************************************************ * Method: takeReservation * Takes: a 2D array that contains seats (the number of * rows and columns) and prices for each seat * (the integer stored in each location of the array) * Returns: nothing (but makes changes to the 2D array) * * What it does: * It lets the user know how many rows of seats and seats per row there are seats ar labled with a row and a;phabetical characters for each seat * so that the user knows what seats s/he can choose from prints with rows and * It asks the user how many seat s/he wants to reserve * It prompts the user to choose the number of seats s/he specified * If all these seats are available, * they are marked as reserved (by putting a 0 in the array * as shown in the lab description), and * the program prints out the transaction's total price * and proposes to the user to make another reservation (proceeds if user agrees, exits otherwise) * Otherwise, * the program should let the user know that some or * all seats are already reserved (and lists them), and * if the user is willing to modify the request: * ask again * otherwise * print out that no transaction took place * exit * Keep doing this until the user either decides not to * modify the request or the request is valid *********************************************************/ public static void takeReservation(int[][] seats) { Scanner input = new Scanner(System.in);

System.out.println("Welcome to the Plaza Theater's seat reservation system!"); // tell user about number of rows and seats and then asks them to input the number of seats they want int c = 15; System.out.println("There are" + "Number of rows :"+seats.length+" " + "and A - " + (char)(c +seats[0].length) + "of seats per Row"); //number of seats in each row; System.out.println("Please enter the number of seats you would like to reserve:");// int noOfSeats = 0; noOfSeats = input.nextInt(); int seatNums[] = new int[noOfSeats]; //declaring a new array based on the number pf seats input String str = ""; while (!str.equalsIgnoreCase("exit")) { int selectedRow[] = new int[noOfSeats];// declaring a new arrayto list seats wanted setting it to the maximum number of seats you could possibly have in an array // invalid seat number boolean notSelected=true; for (int i=0; i showAvailableSeats(seats, i); // next method showing number of seats available int yesNo=0; System.out.println("Enter 1 if you wish to select from this Row else Enter 0"); yesNo=input.nextInt();

if (yesNo == 1){ for (int j=0; j selectedRow[j] = i+1; System.out.println(" Enter seat number "+ (j+1)+" :"); int seatNum = input.nextInt()-1;// -1 brcause we are going by the index System.out.println("selected row" + (i+1) + " seat:"+(seatNum+1)); //again be cause of the indexing seatNums[j]=seatNum+1; //

} notSelected=false; } }

//making reservation int sum = 0; for (int i = 0; i sum = sum + seats[selectedRow[i]][seatNums[i]]; // adding the prices of the selected seats seats[selectedRow[i]][seatNums[i]]=0; //replacing the seats you resaerved with zeros

} System.out.println("*************************************************"); print(seats); System.out.println("*************************************************"); System.out.println("Transaction Reciept"); for ( int i=0 ; i System.out.println("SEAT " + (i+1) + ":Row:" + selectedRow[i] + ":seat:" + (seatNums[i])); } System.out.println("total price of the tickets $" + sum);

System.out.println("Do you want to make another transaction,type : yes Otherwise type exit to quit "); str =input.next(); }

}

/************************************************************************************************************ * Method: showAvailableSeats * Takes: a 2D array that contains seats (the number of * rows and columns) and prices for each seat * (the integer stored in each location of the array) * and 2 integers (min and max) that represent the lower * and upper bound for the price of seats of interest * Returns: nothing * * What it does: * It prints out all the seats in the 2D array that are within the * price range specified by [min, max] * If there is no such seat, the user is told so. *********************************************************/ public static void showAvailableSeats(int[][] seats, int min, int max) { int count = 0; for (int i = 0; i < seats.length; i++) { for (int j = 0; j < seats[0].length; j++) { // your code goes here if (seats[i][j] >= min && seats[i][j] <= max && seats[i][j]!=0) { // if seats are more than min and less than max and they are not labled zero count++;

System.out.print(seats[i][j]+" "); } } } System.out.println(); if (count == 0) System.out.println("It looks like there is no seat that matches your price requirements."); // if the variable stored is = 0 }

/************************************************************************************************************ * Method: showAvailableSeats * Takes: a 2D array that contains seats (the number of * rows and columns) and prices for each seat * (the integer stored in each location of the array) * and 1 integer (row) that represent the row of the seats * of interest * Returns: nothing * * What it does: * It prints out all the seats in the 2D array that are within the * given row and available * If there is no such seat, the user is told so. *********************************************************/ public static void showAvailableSeats(int[][] seats, int row) { int seatsAva = 0; for (int j = 0; j < seats[0].length; j++) { if(seats[row][j]!=0){ // if place in array is not zero seatsAva++; System.out.print(seats[row][j]+" "); } } System.out.println(); if (seatsAva == 0) System.out.println("It looks like there is no seat available in row " + row + "."); }

/************************************************************************************************************ * Method: copy (non recursive: using loops) * Takes: a 2D array that contains seats (the number of * rows and columns) and prices for each seat * (the integer stored in each location of the array) * Returns: a 2D array which is a replica of the input 2D array *********************************************************/ public static int[][] copy(int[][] seats) { int[][] backUp = new int[seats.length][seats[0].length]; for(int i=0;i for(int j=0;j { backUp[i][j] = seats[i][j]; }

return backUp; }

/************************************************************************************************************ * Method: copyR (recursive: no loop) * Takes: a 2D array that contains seats (the number of * rows and columns) and prices for each seat * (the integer stored in each location of the array) * Creates (but does not return): a 2D array which is a replica of the input 2D array * * copyR uses what is at times called an "auxiliary" method: copyRowR * which copies a given row of the input of copyR into the expected output 2D array of copyR *********************************************************/ public static void copyR(int[][] seats, int[][] result, int start) { // your code goes here if (start >= seats.length) return; result[start] = seats[start]; copyR(seats, result, start+1); }

/************************************************************************************************************ * Method: copyRowR (recursive: no loop) * Takes: a 1D array that represents a row of the input of method copyR * Creates (but does not return): a 1D array which is a replica of the input 1D array *********************************************************/ public static void copyRowR(int[] seatsRow, int[] resultRow, int init) { if (init >= seatsRow.length) return; resultRow[init] = seatsRow[init]; copyRowR(seatsRow, resultRow, init+1); }

/************************************************************************************************************ * Method: print * Takes: a 2D array that contains seats (the number of * rows and columns) and prices for each seat * (the integer stored in each location of the array) * Returns: nothing * Prints the content of the input 2D array (row by row) *********************************************************/ public static void print(int[][] A) { // your code goes here System.out.println("Printing backup"); for(int i=0;i for(int j=0;j System.out.print(A[i][j]+" "); // Prints Array and a space between elements of Array } System.out.println(); } }

/*************************************************************************************************************** * This is the main method, from which all above methods are being used * Do not modify this method. ***************************************************************************************************************/ public static void main(String[] args) {

Scanner in = new Scanner(System.in); String answer; int min, max, row;

// load a 2D array of prices int[][] seatsAndPrices = loadInfo(5,10);

// copy seatsAndPrices in a backup 2D array in case we need to change reservations int[][] backUp = copy(seatsAndPrices); // int[][] backUp = new int[seatsAndPrices.length][seatsAndPrices[0].length]; copyR(seatsAndPrices, backUp, 0); print(backUp);

// runs the method that shows seats within a given price range System.out.println("Would you like to see the seats options within a chosen price range?"); answer = in.next(); if (answer.toLowerCase().compareTo("yes")==0) { System.out.println("What is the max anount you are ready to pay for a seat?"); max = in.nextInt(); System.out.println("What is the lowest price you'd like to consider?"); min = in.nextInt(); showAvailableSeats(seatsAndPrices, min, max); }

// runs the method that shows seats within a given row System.out.println("Would you like to see the available seats in a given row?"); answer = in.next(); if (answer.toLowerCase().compareTo("yes")==0) { System.out.println("What row are you interested in?"); row = in.nextInt(); showAvailableSeats(seatsAndPrices, row); }

// runs the reservation method takeReservation(seatsAndPrices); } }

**************************************************************************************************************************************************

******************************************************************************************************************************************************You are in charge of seat reservation for the plaza theater. Different seats have different prices. You hold the list of prices in a 2D array where rows of the array correspond to rows of seats, and where the first row in the array corresponds to the row closest to the stage and the last row of the array corresponds to the row farthest to the stage

For instance, here is an example of such an array:

50 50 60 60 80 80 60 60 50 50

50 50 60 60 80 80 60 60 50 50

40 40 50 50 70 70 50 50 40 40

40 40 50 50 70 70 50 50 40 40

35 35 45 45 65 65 45 45 35 35 where the top row represents the seats that are closest to the stage.

Your job is to design a series of methods that allow you to do the following: Take reservations: o A client comes and asks to reserves three seats: in row 3, seats D, E, and F. You need to be able to tell him or her whether the seats are available or not. If they are, you need to set the corresponding values in your array to 0 In case the seats to be reserved are already taken, your program should keep asking the user to select new seats, but give him or her the possibility to give up and exit your program. o More details available in the java file lab12.java. Note that we are numbering the seats as follows: a number followed by a letter. The number indicates the row number and the letter indicates the seat location in that row, lettering from left to right. Show available seats: o Per price: A client comes and asks to see all available seats whose price falls in a given bracket: your job is to print out all of these seats. For instance, in the above example, if a client wants to know all available seats whose price is between $30 and < $40, your program should output the following information: 5A 5B 5I 5J o Per row: A client comes and asks to see all available seats in a given row: your job is to print out all of these seats. For instance, in the above example, if a client wants to know all available seats in row 3, your program should output the following information: 3A 3B 3C 3G 3H 3I 3J o More details available in the java file lab12.java.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!