Commit b875b8ff authored by User's avatar User

edit

parent 1a2e034b
...@@ -5,6 +5,7 @@ public class reservation { ...@@ -5,6 +5,7 @@ public class reservation {
public static void main(String[] args) {//main subprogram public static void main(String[] args) {//main subprogram
Scanner input = new Scanner(System.in); Scanner input = new Scanner(System.in);
int choice = 0; int choice = 0;
String reserve = "";
String plane[][] = {{"XX", "02", "XX"}, {"04", "05", "06"}, {"07", "08", "09"}, //initialise the array which contains the plane seats String plane[][] = {{"XX", "02", "XX"}, {"04", "05", "06"}, {"07", "08", "09"}, //initialise the array which contains the plane seats
{"10", "11", "12"}, {"13", "14", "15"}, {"16", "17", "18"}, {"10", "11", "12"}, {"13", "14", "15"}, {"16", "17", "18"},
{"19", "20", "21"}, {"22", "23", "24"}, {"25", "26", "27"}, {"19", "20", "21"}, {"22", "23", "24"}, {"25", "26", "27"},
...@@ -38,10 +39,37 @@ public class reservation { ...@@ -38,10 +39,37 @@ public class reservation {
switch(choose) { switch(choose) {
case "N": case "N":
System.out.println("Ok, You will be assigned the next available seat"); System.out.println("Ok, You will be assigned the next available seat");
for(int s=0; s<1; s++) {
for(int r=0; r<3; r++) {
if(plane[s][r] != "XX") {
reserve = plane[s][r];
plane[s][r] = "XX";
System.out.println("Your booked seat is " + reserve);
ticket();
return;
}
}
}
return; return;
case "Y": case "Y":
System.out.println("Ok please choose a seat:"); System.out.println("Ok please choose a seat:"
+ "\n Here is the plane seat layout");
display(plane);
System.out.println("\nSeat choice: ");
reserve = input.next();
for(int s=0; s<1; s++) {
for(int r=0; r<3; r++) {
System.out.println(plane[s][r] + reserve);
if(plane[s][r] != reserve) {
System.out.println("Seat " + reserve + " has been booked for you");
plane[s][r] = "XX";
display(plane);
return;
}
}
System.out.println("Invalid input. Please choose an available seat. Seats with XX have been booked already and are not available");
return; return;
}
default: default:
System.out.println("invalid input please choose Y or N"); System.out.println("invalid input please choose Y or N");
break; break;
...@@ -65,7 +93,6 @@ public class reservation { ...@@ -65,7 +93,6 @@ public class reservation {
} }
} }
} }
//return;
case 2://case if user chooses business class/2 case 2://case if user chooses business class/2
System.out.println("You have Chosen Business Class");//prints out the class that the user has chosen System.out.println("You have Chosen Business Class");//prints out the class that the user has chosen
break; break;
...@@ -77,7 +104,6 @@ public class reservation { ...@@ -77,7 +104,6 @@ public class reservation {
break; break;
} }
} }
} }
public static void display(String plane[][]) {//create method called "display" public static void display(String plane[][]) {//create method called "display"
...@@ -153,5 +179,8 @@ public class reservation { ...@@ -153,5 +179,8 @@ public class reservation {
System.out.print("\t"); System.out.print("\t");
} }
} }
public static void ticket() {
System.out.println("END");
}
} }
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