Commit ff5b6713 authored by charlie.hamer's avatar charlie.hamer

Finished

parent e9b7b80c
import java.util.Scanner; //import scanner import java.util.Scanner; //import scanner
import java.util.Random; //I don't know the requirements for generating a flight code, so I will generate one randomly import java.util.Random; //I don't know the requirements for generating a flight code, so I will generate one randomly
import java.util.Arrays;
import java.util.List;
public class airline { public class airline {
static String plane[][] = {{"01", "02", "03"}, {"04", "05", "06"}, {"07", "08", "09"}, // set plane as global variable static String plane[][] = {{"01", "02", "03"}, {"04", "05", "06"}, {"07", "08", "09"}, // set plane as global variable
{"10", "11", "12"}, {"13", "14", "15"}, {"16", "17", "18"}, {"10", "11", "12"}, {"13", "14", "15"}, {"16", "17", "18"},
...@@ -22,7 +24,6 @@ public class airline { ...@@ -22,7 +24,6 @@ public class airline {
static Random random = new Random(); static Random random = new Random();
public static void main(String[] args) { public static void main(String[] args) {
System.out.print(plane[0][0]);
details(); //to allow repeatability at the end of the program details(); //to allow repeatability at the end of the program
} }
...@@ -72,9 +73,9 @@ public class airline { ...@@ -72,9 +73,9 @@ public class airline {
boolean available = false; boolean available = false;
System.out.println("You have chosen First Class"); //confirms class System.out.println("You have chosen First Class"); //confirms class
for(int i=0; i<1; i++) { for(int i=0; i<6; i++) {
for(int j=0; j<3; j++) { for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") { if(!plane[i][j].contentEquals("XX")) {
available = true; //checking if seats are available available = true; //checking if seats are available
} }
else else
...@@ -107,9 +108,9 @@ public class airline { ...@@ -107,9 +108,9 @@ public class airline {
boolean available = false; boolean available = false;
System.out.println("You have chosen Business"); //confirms class System.out.println("You have chosen Business"); //confirms class
for(int i=2; i<4; i++) { for(int i=6; i<15; i++) {
for(int j=0; j<3; j++) { for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") { if(!plane[i][j].contentEquals("XX")) {
available = true; //checking if seats are available available = true; //checking if seats are available
} }
else else
...@@ -145,9 +146,9 @@ public class airline { ...@@ -145,9 +146,9 @@ public class airline {
boolean available = false; boolean available = false;
System.out.println("You have chosen Economy"); //confirms class System.out.println("You have chosen Economy"); //confirms class
for(int i=5; i<9; i++) { for(int i=15; i<30; i++) {
for(int j=0; j<3; j++) { for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") { if(!plane[i][j].contentEquals("XX")) {
available = true; //checking if seats are available available = true; //checking if seats are available
} }
else else
...@@ -201,7 +202,7 @@ public class airline { ...@@ -201,7 +202,7 @@ public class airline {
case "First Class": case "First Class":
for(int i=0; i<1; i++) { for(int i=0; i<1; i++) {
for(int j=0; j<3; j++) { for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") { //checks through seats, finds one that hasn't been filled yet if(!seat.contentEquals(plane[i][j])) { //checks through seats, finds one that hasn't been filled yet
seat = plane[i][j]; seat = plane[i][j];
plane[i][j] = "XX"; plane[i][j] = "XX";
break; break;
...@@ -211,7 +212,7 @@ public class airline { ...@@ -211,7 +212,7 @@ public class airline {
case "Business": case "Business":
for(int i=2; i<4; i++) { for(int i=2; i<4; i++) {
for(int j=0; j<3; j++) { for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") { //checks through seats, finds one that hasn't been filled yet if(!seat.contentEquals(plane[i][j])) { //checks through seats, finds one that hasn't been filled yet
seat = plane[i][j]; seat = plane[i][j];
plane[i][j] = "XX"; plane[i][j] = "XX";
break; break;
...@@ -221,7 +222,7 @@ public class airline { ...@@ -221,7 +222,7 @@ public class airline {
case "Economy": case "Economy":
for(int i=5; i<9; i++) { for(int i=5; i<9; i++) {
for(int j=0; j<3; j++) { for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") { //checks through seats, finds one that hasn't been filled yet if (!seat.contentEquals(plane[i][j])) { //checks through seats, finds one that hasn't been filled yet
seat = plane[i][j]; seat = plane[i][j];
plane[i][j] = "XX"; plane[i][j] = "XX";
break; break;
...@@ -242,44 +243,54 @@ public class airline { ...@@ -242,44 +243,54 @@ public class airline {
switch(fclass) { switch(fclass) {
case "First Class": case "First Class":
seat = input.next(); seat = input.next();
for(int i=0; i<6; i++)
for(int j=0; j<3; j++) {
System.out.println(plane[i][j]);
if (seat == plane[i][j])
plane[i][j] = "XX";
}
if (Integer.parseInt(seat) > 18) { //making sure the seat they choose is in their chosen class if (Integer.parseInt(seat) > 18) { //making sure the seat they choose is in their chosen class
chooseseat(fclass); } chooseseat(fclass); }
boardingpass(fclass);//loads up the boarding class for(int i=0; i<6; i++)
for(int j=0; j<3; j++) {
if (seat.contentEquals(plane[i][j])) {
plane[i][j] = "XX";
if (Integer.parseInt(seat) > 18) { //making sure the seat they choose is in their chosen class
chooseseat(fclass); }
boardingpass(fclass);//loads up the boarding class
}
}
System.out.println("Sorry, that seat is taken");
chooseseat(fclass);
break; break;
case "Business": case "Business":
seat = input.next(); seat = input.next();
for(int i=6; i<15; i++) { for(int i=6; i<15; i++)
for(int j=0; j<3; j++) { for(int j=0; j<3; j++) {
if (seat == plane[i][j]) if (seat.contentEquals(plane[i][j])) {
plane[i][j] = "XX"; plane[i][j] = "XX";
if (Integer.parseInt(seat) < 18) {//making sure the seat they choose is in their chosen class
chooseseat(fclass);}
if (Integer.parseInt(seat) > 45) {
chooseseat(fclass);}
boardingpass(fclass);//loads up the boarding class
}
if(plane[i][j].contentEquals("XX")){
System.out.println("Sorry, that seat is taken");
chooseseat(fclass);}
} }
if (Integer.parseInt(seat) < 18) {//making sure the seat they choose is in their chosen class
chooseseat(fclass);}
if (Integer.parseInt(seat) > 45) {
chooseseat(fclass);}
boardingpass(fclass);//loads up the boarding class
}
break; break;
case "Economy": case "Economy":
seat = input.next(); seat = input.next();
for(int i=15; i<30; i++) { for(int i=15; i<30; i++)
for(int j=0; j<3; j++) { for(int j=0; j<3; j++) {
if (seat == plane[i][j]) if (seat.contentEquals(plane[i][j])) {
plane[i][j] = "XX"; plane[i][j] = "XX";
if (Integer.parseInt(seat) < 46) { //making sure the seat they choose is in their chosen class
} chooseseat(fclass); }
if (Integer.parseInt(seat) < 45) {//making sure the seat they choose is in their chosen class boardingpass(fclass);//loads up the boarding class
chooseseat(fclass);} }
boardingpass(fclass);//loads up the boarding class if(plane[i][j].contentEquals("XX")){
System.out.println("Sorry, that seat is taken");
chooseseat(fclass);}
}
break; break;
}
} }
} }
......
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