Commit 3d89b2ce authored by oscar.harding's avatar oscar.harding

RestaurantBookingSystem

parent 3c54c9dd
package RestaurantBookingSystem;
import java.lang.reflect.Array;
import java.util.*;
public class restaurant {
// I SHOULD HAVE DONE MOST OF THIS USING METHOD TO START WITH BUT I WAS GOING BACK THROUGH TRYING TO CHANGE IT AND STRUGGLED TO GET IT WORKING AGAIN - SORRY.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//Ask Customer for their name
System.out.println("Hello, what is your name? ");
String name = scanner.nextLine();
//layout of the tables
//filled it in manually cause i found it easier to correctly format it and test for empty seats that way
String courtyard[][] = {{"[01]", "[02]", "[03]","[04]","[05]","[06]","[07]",},
{"[08]", "[09]", "[10]","[11]","[12]","[13]","[14]",},
{" ", " ", " "," "," "," "," ",},
{"[15]", "[16]", "[17]","[18]","[19]","[20]","[21]",},
{"[22]", "[23]", "[24]","[25]","[26]","[27]","[28]",},
{" ", " ", " "," "," "," "," "},
{"[29]", "[30]", "[31]","[32]","[33]","[34]","[35]",},
{"[36]", "[37]", "[38]","[39]","[40]","[41]","[42]",}};
//Display table layout
display(courtyard);
//Check that there are seats available, if not, display message
int TakenSeats = 0;
for(int i=0; i<8; i++) {
for(int j = 0; j<7; j++) {
if(courtyard[i][j] == "[XX]") {
TakenSeats = TakenSeats+1;//counting how many taken seats there are
if (TakenSeats == 42) {//at 42 occupied seats the courtyard is full, display message saying so
System.out.println("Sorry, " + name + ", there are no seats available at this time.");
}
}
}
}
//Ask the customer if they have a preferred seat
Scanner scanner1 = new Scanner(System.in);
System.out.println(name + ", above is the seating layout for our courtyard. If you have a preferred seat, please enter the number of it now. If not, just press enter.");
String Seatchoice = scanner1.nextLine();
Seatchoice = "[" + Seatchoice + "]";
//Assign Seatchoice if it has been left blank
if (Seatchoice.equals("[]")) {
for(int i=7; i>=0; i--) {
for(int j = 6; j>=0; j--) {//not a very elegant solution but making it go from largest to smallest so it lands on the first available seat at the end.
if (!courtyard[i][j].equals("[XX]")){
if (!courtyard[i][j].equals(" ")) {
Seatchoice = courtyard[i][j];
}
}
}
}
}
System.out.println ("You have selected seat " +Seatchoice);//Display to the customer their seat number.
//mark seat as occupied
int seatcount = 0;//seatcount variable counts whenever a position in the courtyard is not the desired seat number
for(int i=0; i<8; i++) {
for(int j = 0; j<7; j++) {
if(courtyard[i][j].equals(Seatchoice)) {//Mark the seat as occupied if it is a valid entry
courtyard[i][j] = "[XX]";
display(courtyard);//display updated courtyard layout.
seatcount = 0;
}
else if(!courtyard[i][j].equals(Seatchoice)) {//add one to seatcount if the seat number entered does not correspond to a seat in the courtyard. See below.
seatcount = seatcount+1;
}
if(seatcount == 56) {//if none of the positions in the courtyard are the seat number entered, it must be an invalid entry.
System.out.println("That is not an available seat, please try again.");//hence this error message
seatcount = 0;
}
}
}
}
//method for displaying tables
static void display(String courtyard[][]) {
for(int i=0; i<8; i++) {
for(int j = 0; j<7; j++) {
System.out.print(courtyard[i][j]);
}
System.out.println();
}}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment