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

First, got that weird for loop stuff

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AirlineReservation</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
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
public class airline {
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"},
{"19", "20", "21"}, {"22", "23", "24"}, {"25", "26", "27"},
{"28", "29", "30"}, {"31", "32", "33"}, {"34", "35", "36"},
{"37", "38", "39"}, {"40", "41", "42"}, {"43", "44", "45"},
{"46", "47", "48"}, {"49", "50", "51"}, {"52", "53", "54"},
{"55", "56", "57"}, {"58", "59", "60"}, {"61", "62", "63"},
{"64", "65", "66"}, {"67", "68", "69"}, {"70", "71", "72"},
{"73", "74", "75"}, {"76", "77", "78"}, {"79", "80", "81"},
{"82", "83", "84"}, {"85", "86", "87"}, {"88", "89", "90"}};
static Scanner input = new Scanner(System.in); // global scanner
static String name; static String ocity; static String dcity; //assigning global variables for customer details
static String seat;
static String [] flight = {"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", }; //generating the random flight numbers
static Random random = new Random();
public static void main(String[] args) {
System.out.print(plane[0][0]);
details(); //to allow repeatability at the end of the program
}
public static void details() {
System.out.print("What is your name?");
name = input.next();
System.out.print("Where will you be flying from?");
ocity = input.next();
System.out.print("Where are you flying to?");
dcity = input.next(); // getting customer details
Class();
}
public static void Class(){
int fclass ; //variable to determine class
System.out.print("Choose a flight class-"
+ "\nPlease type 1 for First Class"
+ "\nPlease type 2 for Business"
+ "\nPlease type 3 for Economy \n");
switch(fclass = input.nextInt()) {
case 1: //if user chooses first class
first();
break;
case 2://if user chooses business class
business();
break;
case 3://case if user chooses economy class
economy();
break;
default://case if user chooses an invalid option
System.out.println("Invalid option. Please choose a number from 1 to 3");//prints out an error message
break;
}
}
private static void first() {
String fclass = "First Class";
boolean available = false;
System.out.println("You have chosen First Class"); //confirms class
for(int i=0; i<1; i++) {
for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") {
available = true; //checking if seats are available
}
else
available = false;
}
}
if(available == true) { //if seats are available
System.out.println("Would you like to choose a seat?(y/n)");
String chooseseat = input.next();
switch(chooseseat) {
case "n":
System.out.println("You will be assigned a seat"); //if user doesn't want to choose seat the subroutine to assign them one runs
assign(fclass);
case "y":
System.out.println("Choose a seat:");//otherwise they'll be sent to the subroutine to pick a seat
chooseseat(fclass);
return;
default:
System.out.println("Please pick y or n");//making sure they make a choice
}
}
else
noseat(); //if there are no seats available
}
private static void business() {
String fclass = "Business";
boolean available = false;
System.out.println("You have chosen Business"); //confirms class
for(int i=2; i<4; i++) {
for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") {
available = true; //checking if seats are available
}
else
available = false;
}
}
if(available == true) {//if seats are available
System.out.println("Would you like to choose a seat?(y/n)");
String chooseseat = input.next();
switch(chooseseat) {
case "n":
System.out.println("You will be assigned a seat");//if user doesn't want to choose seat the subroutine to assign them one runs
assign(fclass);
return;
case "y":
System.out.println("Choose a seat:");//otherwise they'll be sent to the subroutine to pick a seat
chooseseat(fclass);
return;
default:
System.out.println("Please pick y or n");//making sure they make a choice
break;
}
}
else
noseat(); //if there are no seats available
}
private static void economy() {
String fclass = "Economy";
boolean available = false;
System.out.println("You have chosen Economy"); //confirms class
for(int i=5; i<9; i++) {
for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") {
available = true; //checking if seats are available
}
else
available = false;
}
}
if(available == true) {//if seats are available
System.out.println("Would you like to choose a seat?(y/n)");
String chooseseat = input.next();
switch(chooseseat) {
case "n":
System.out.println("You will be assigned a seat");//if user doesn't want to choose seat the subroutine to assign them one runs
assign(fclass);
return;
case "y":
System.out.println("Choose a seat:");//otherwise they'll be sent to the subroutine to pick a seat
chooseseat(fclass);
return;
default:
System.out.println("Please pick y or n");//making sure they make a choice
break;
}
}
else
noseat(); //if there are no seats available
}
private static void noseat() {
while(true){
System.out.println("There are no more seats in that class, can we move you to a different class?");
String noseat = input.next();
switch(noseat) {
case "n":
System.out.println("We are afraid we cannot accomodate you. The next flight to " + dcity +" is in 6 hours" ); //ends the program for them to restart for the next flight
return;
case "y":
Class();//takes them back to the class selection
return;
default:
System.out.println("Please pick y or n");
break;
}
}
}
private static void assign(String fclass) {
switch(fclass) {
case "First Class":
for(int i=0; i<1; i++) {
for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") { //checks through seats, finds one that hasn't been filled yet
seat = plane[i][j];
plane[i][j] = "XX";
break;
}
}
}
case "Business":
for(int i=2; i<4; i++) {
for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") { //checks through seats, finds one that hasn't been filled yet
seat = plane[i][j];
plane[i][j] = "XX";
break;
}
}
}
case "Economy":
for(int i=5; i<9; i++) {
for(int j=0; j<3; j++) {
if(plane[i][j] != "XX") { //checks through seats, finds one that hasn't been filled yet
seat = plane[i][j];
plane[i][j] = "XX";
break;
}
}
}
}
boardingpass(fclass); //loads up the boarding class
}
public static void chooseseat(String fclass) {
display();
System.out.println("");
System.out.println("Please choose a seat in your class");
System.out.println("1-18 is First Class, 19-45 is Business, 46-90 is Economy");
switch(fclass) {
case "First Class":
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
chooseseat(fclass); }
boardingpass(fclass);//loads up the boarding class
break;
case "Business":
seat = input.next();
for(int i=6; i<15; i++) {
for(int j=0; j<3; 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
chooseseat(fclass);}
if (Integer.parseInt(seat) > 45) {
chooseseat(fclass);}
boardingpass(fclass);//loads up the boarding class
}
break;
case "Economy":
seat = input.next();
for(int i=15; i<30; i++) {
for(int j=0; j<3; j++) {
if (seat == plane[i][j])
plane[i][j] = "XX";
}
if (Integer.parseInt(seat) < 45) {//making sure the seat they choose is in their chosen class
chooseseat(fclass);}
boardingpass(fclass);//loads up the boarding class
break;
}
}
}
private static void boardingpass(String fclass) {
int select = random.nextInt(flight.length); //randomly generates the flight number
System.out.println("This is your boarding pass:");
System.out.println("");
System.out.println("|[ BOARDING PASS ]|");
System.out.println("Name : " + name);
System.out.println("From : " + ocity);
System.out.println("To : " + dcity);
System.out.println("Flight : FL" + flight[select]);
System.out.println("Seat No. : " + seat);
System.out.println("Section : " + fclass);
display();
System.out.println("");
System.out.println("Would you like to book another?");//the choice to restart the program essentially
String again = input.next();
switch(again) {
case "y":
details();
default:
System.out.println("Thank you for shopping with us today");
}
}
public static void display() { //purely all for displaying the seating chart
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
System.out.print("[" + plane[i][j] + "]");
}
System.out.print("\t");
}
System.out.println();
for(int i=3; i<6; i++) {
for(int j=0; j<3; j++) {
System.out.print("[" + plane[i][j] + "]");
}
System.out.print("\t");
}
System.out.println();
System.out.println();
for(int i=6; i<9; i++) {
for(int j=0; j<3; j++) {
System.out.print("[" + plane[i][j] + "]");
}
System.out.print("\t");
}
System.out.println();
for(int i=9; i<12; i++) {
for(int j=0; j<3; j++) {
System.out.print("[" + plane[i][j] + "]");
}
System.out.print("\t");
}
System.out.println();
for(int i=12; i<15; i++) {
for(int j=0; j<3; j++) {
System.out.print("[" + plane[i][j] + "]");
}
System.out.print("\t");
}
System.out.println();
System.out.println();
for(int i=15; i<18; i++) {
for(int j=0; j<3; j++) {
System.out.print("[" + plane[i][j] + "]");
}
System.out.print("\t");
}
System.out.println();
for(int i=18; i<21; i++) {
for(int j=0; j<3; j++) {
System.out.print("[" + plane[i][j] + "]");
}
System.out.print("\t");
}
System.out.println();
for(int i=21; i<24; i++) {
for(int j=0; j<3; j++) {
System.out.print("[" + plane[i][j] + "]");
}
System.out.print("\t");
}
System.out.println();
for(int i=24; i<27; i++) {
for(int j=0; j<3; j++) {
System.out.print("[" + plane[i][j] + "]");
}
System.out.print("\t");
}
System.out.println();
for(int i=27; i<30; i++) {
for(int j=0; j<3; j++) {
System.out.print("[" + plane[i][j] + "]");
}
System.out.print("\t");
}
}
}
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