Hi im having trouble returning a array from a method, ive highlighted these section's of code in red, can any help me with this or recommend a thread where i can read up on the solution to my problem
Here's the Assignment question i was given.
Write a program that simulates the booking of seats on board a small airplane. The layout of the aircraft is illustrated
below. You will be required to create a menu based system with the following choices:
(a) View Seating (b) Book a Seat (c) Cancel a Booking (d) Reset All (e) Quit
Each of the above will require a method which takes an array as a parameter. You can of course add more options to
this basic menu list if you wish. However at all times the user should be able to view the state of the aircraft bookings
i.e. option (a) and thus be presented with a representation of a 2D array similar to that below:
You are required to output the current values of the array to show the current seating arrangement in graphic format. As
can be seen, you will need output some space for an aisle to separate columns A and B from columns C and D.
Similarly rows 1-4 (non-smoking) should be output separately from rows 5 – 6 (smoking)
The grid references should also be output to the screen. A,B,C and D for the columns and 1-8 for the rows. You don’t
have to simulate the box effect as in the diagram above, but try to keep the output as clear as possible with all reference
points indicated.
Use ‘X’ to indicate that a seat is booked and a hyphen ‘-‘ to indicate that the seat is still available.
Bookings can be made by selecting option (b) At which point the user is asked which seat number (reference) they
wish to book. For example, seat B4 is selected in the diagram above.
Option (c) should allow the user to enter a booked seat reference and make it available again. Option (d) Should reset
the bookings and free up ALL seats once again.
Things to consider : Smoking or Non-Smoking:
Seats in rows 5,6,7 and 8 are designated as smoking seats. When making a booking - option (c) - the user should be
asked their preference (Smoking or non-smoking?) If for example they choose smoking and all seats are full in that
section, they should be informed of this and offered a seat in the non-smoking section. If the seats are not full in the
smoking section and they proceed to enter a reference number that is in the non-smoking section, they should be
prompted to confirm their choice. The same should apply to seats chosen in the non-smoking section
class abc { public static void main(String[] args) //calling of methods from main method { char choice; char array1[][] = new char[8][4]; do { System.out.println("please choose from the options below"); System.out.println("(a) View Seating (b) Book a Seat (c) Cancel a Booking (d) Reset All (e) Quit"); choice = Keyboard.readChar(); switch(choice) { case 'a':viewseating(array1);break; case 'b':bookseat(array1);break; case 'c':cancel(array1);break; case 'd':reset(array1);break; case 'e':System.out.println("thank you goodbye");break; default: System.out.print("Enter (a)(b)(c)(d)(e)"); }//close switch }while(choice != 'e'); }//close main /*****************************************************************************************************************/ static void viewseating(char array1[][])//output array { int i, j; for(i=1; i<=4; i++) { for(j=1; j<=2; j++) { System.out.println(array1[i][j]); }//close inner for }//close outer for System.out.print("\n\n\n\n\n"); for(i=1; i<= 4; i++) { for(j=3; j<=4; j++) { System.out.println(array1[i][j]); }//close inner for }//close outer for System.out.println(""); for(i=5; i<=8; i++) { for(j=1; j<=2; j++) { System.out.println(array1[i][j]); }//close inner for }//close outer for System.out.print("\n\n\n\n\n"); for(i=5; i<=8; i++) { for(j=3; j<=4; j++) { System.out.println(array1[i][j]); }//close inner for }//close outer for }//close method viewseating /******************************************************************************************************************/ static char bookseat(char array1[][])//to do//assign values to a =1 b = 2 c =3 d = 4 ??for array??//needs if statement to check if seat is booked already { int seat, i, j; char row; char ans, ans1; array1[row][seat] = array1[i][j]; System.out.println("would you like smoking or non smoking"); System.out.println("press (a) for smoking or (b) for non smoking"); ans = Keyboard.readChar(); while(ans != 'a' && ans != 'b')//validating that correct letters have been entered { System.out.println("Please choose either (a) for smoking or (b) for non smoking"); ans = Keyboard.readChar(); } if(ans == 'a') { System.out.println("please enter the row you wish to sit in (a)(b)(c)(d)"); row = Keyboard.readChar(); while(row != 'a' && row != 'b' && row !='c' && row != 'd')//validating that correct letters have been entered { System.out.println("There are only four rows (a)(b)(c)(d) please choose one"); row = Keyboard.readChar(); }//close while System.out.println("please enter the seat number you wish to sit in"); seat = Keyboard.readInt(); while(seat > 4) { System.out.println("seat "+seat+ "is not in the smoking section"); System.out.println("please choose a seat from the smoking section 1 - 4"); System.out.println("please enter the seat number you wish to sit in"); seat = Keyboard.readInt(); }//close while System.out.println("are you sure you want to book this seat row"+row+" seat number "+seat); System.out.println("press (y) for yes and (n) for no"); ans1= Keyboard.readChar(); while(ans1 != 'y' && ans1 != 'n')//validating that correct letters have been entered { System.out.println("Please choose either (y) for yes or (n) for no"); ans1 = Keyboard.readChar(); } if(ans1 == 'y') { System.out.println("you have succesfully booked a seat row "+row+" seat number "+seat); }//close if if(ans1 == 'n') { System.out.println("you will be returned to the main menu"); }//close if }//close if if(ans == 'b') { System.out.println("please enter the row you wish to sit in"); row = Keyboard.readChar(); while(row != 'a' && row != 'b' && row !='c' && row != 'd')//validating that correct letters have been entered { System.out.println("There are only four rows (a)(b)(c)(d) please choose one"); row = Keyboard.readChar(); }//close while System.out.println("please enter the seat number you wish to sit in"); seat = Keyboard.readInt(); while(seat < 4 && seat > 8) { System.out.println("seat "+seat+ "is not in the non smoking section"); System.out.println("please choose a seat from the non smoking section, seat 5 to 8"); System.out.println("please enter the seat number you wish to sit in"); seat = Keyboard.readInt(); }//close while loop System.out.println("are you sure you want to book this seat row "+row+" seatnumber "+seat); System.out.println("press (y) for yes and (n) for no"); ans1= Keyboard.readChar(); while(ans1 != 'y' && ans1 != 'n')//validating that correct letters have been entered { System.out.println("Please choose either (y) for yes or (n) for no"); ans1 = Keyboard.readChar(); } if(ans1 == 'y') { System.out.println("you have succesfully booked seat row "+row+" seat number "+seat); }//close if if(ans1 == 'n') { System.out.println("you will be returned to the main menu"); }//close if }//close if [COLOR="Red"]return (array1);[/COLOR] }//close bookseat method /**************************************************************************************************************************************/ static char cancel(char array1[][]) { } /**************************************************************************************************************************************/ static char reset(char array1[][]) { int i, j; char ans2; System.out.println("are you sure you want to reset the table (y) or (n)"); ans2=Keyboard.readChar(); while(ans2 != 'y' && ans2 != 'n')//validating that correct letters have been entered { System.out.println("Please choose either (y) for yes or (n) for no"); ans2 = Keyboard.readChar(); }//close while loop if(ans2 == 'y') { for(i = 0; i <array1.length; i++) { for(j = 0; j <array1.length; j++) {//[COLOR="Blue"]Missing code[/COLOR] }//close inner for }//close outer for System.out.println("All seats on the airplane have been reset to available"); }//close if else { System.out.println("You will be returned to the main menu"); }//close else [COLOR="red"]return (array1);[/COLOR] }//close reset method /*************************************************************************************************************************************/ }//close class