Commit 7bbc3ed6 authored by ryanw's avatar ryanw

Assignment upload

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Assignment_</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>
import java.util.Random;
import java.util.Scanner;
public class Airoplane_Seat_System
{
//2d array for the seating plan
static String seating[][] = {{"[XX]", "02", "[XX]","[XX]","[XX]","06","07","08","09"},
{"10", "11", "[XX]","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"},
{"[XX]", "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"}};
private static String name;
private static String depart;
private static String dest;
private static int flightNum;
private static String section;
private static String seatChoice;
static Scanner input = new Scanner(System.in);
public static void main(String[] args)
{
customerDetails();
flightNumber();
boolean seatMenu = true;
while(seatMenu)
{
seatMenu = seatPlan();
continue;
}
}
public static void customerDetails() //method to obtain relevant customer information
{
System.out.println("\t-----WELCOME TO SEAT SELECTION-----");
System.out.println();
System.out.print("Please enter your name: ");
name = input.next();
System.out.print("Please enter your departure location: ");
depart = input.next();
System.out.print("Please enter your destination: ");
dest = input.next();
System.out.println("\nThank You.");
}
public static void flightNumber() //method for generating a flight number
{
Random num = new Random();
flightNum = num.nextInt(29);
}
//method for displaying seating plan in full
//each seating class is separated out
public static void seatLayout(String seating[][])
{
System.out.println("\t\t -----FIRST CLASS----- ");
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 9; j++)
{
System.out.print(seating[i][j] + "\t");
}
System.out.println();
}
System.out.println("\t\t -----BUSINESS CLASS----- ");
for (int i = 2; i < 5; i++)
{
for (int j = 0; j < 9; j++)
{
System.out.print(seating[i][j] + "\t");
}
System.out.println();
}
System.out.println("\t\t -----ECONOMY CLASS----- ");
for (int i = 5; i < 10; i++)
{
for (int j = 0; j < 9; j++)
{
System.out.print(seating[i][j] + "\t");
}
System.out.println();
}
}
//method for seat/class selection
//user is able to choose between classes and self selection
public static boolean seatPlan()
{
System.out.println("\nHere is the planes seating plan:\n");
System.out.println("Seats marked [XX] have already been booked\n");
seatLayout(seating);
System.out.println("\nPlease select from First, Business or Economy class:");
System.out.println("Select 1 for First Class");
System.out.println("Select 2 for Business Class");
System.out.println("Select 3 for Economy Class");
//System.out.println("Select 4 for Seat Self selection");
int custChoice = input.nextInt();
switch (custChoice) //switch case to move down selected path
{
case 1:
firstClass();
break;
case 2:
businessClass();
break;
case 3:
economyClass();
break;
default:
System.out.println("Invalid choice. Please try again.");
seatPlan();
break;
}
return false;
}
//method for choosing a seat in first class or having a seat assigned for the user
public static void firstClass()
{
System.out.println("Please select how you would like to be seated:"
+ "\nPress 1 to select your own seat."
+ "\nPress 2 to have a seat assigned for you.");
int seatMenu = input.nextInt();
switch (seatMenu)
{
case 1: //case one for user seat selection
System.out.println("\nPlease select where you would like to sit:\n");
System.out.println("Seat maked [XX] are already taken.\n");
seatLayout(seating);
System.out.print("\nSelect row 1 - 2: ");
int row = (input.nextInt()-1);
System.out.print("Select column: 1 - 9: ");
int col = (input.nextInt()-1);
seatChoice = seating[row][col];
if(seatChoice.equals("[XX]"))
{
System.out.println("\n---This seat is already taken---");
System.out.println("---Please select another\n");
firstClass();
}
else if (seatChoice != "[XX]")
{
seating[row][col] = "[XX]";
System.out.println("\nYou have selected seat: " + seatChoice);
seatLayout(seating);
}
section = "First Class";
boardingPass();
break;
case 2: //case 2 the user is assigned a seat
outerLoop: for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 8; j++)
{
if(!(seating[i][j].equals("[XX]")))//test to find available seat, and assign the next available seat
{
seatChoice = seating[i][j];
seating[i][j] = "[XX]";
break outerLoop;
}
if(seating[1][8].equals("[XX]"))//test to find if all seats are occupied and allow user to move if required
{
System.out.println("All First seats are full. If you would like a seat in: "
+ "\nBusiness class press 1."
+ "\nEconomy press 2. "
+ "\nElse press 3: ");
String choice = input.next();
if(choice.equals("1"))
{
businessClass();
}
else if(choice.equals("2"))
{
economyClass();
}
else
System.out.println("All seat are booked. The next flight is in 6 hours.");
System.exit(0);
}
}
System.out.println();
}
section = "First Class";
boardingPass();
break;
default:
System.out.println("Invalid input. Please try again.");
firstClass();
break;
}
}
//method for choosing a seat in business or having a seat assigned for the user
public static void businessClass()
{
System.out.println("Please select how you would like to be seated:"
+ "\nPress 1 to select your own seat."
+ "\nPress 2 to have a seat assigned for you.");
int seatMenu = input.nextInt();
switch (seatMenu)
{
case 1: //case 1 for user self selection
System.out.println("\nPlease select where you would like to sit:\n");
System.out.println("Seat maked [XX] are already taken.\n");
seatLayout(seating);
System.out.print("\nSelect row 3 - 5: ");
int row = (input.nextInt()-1);
System.out.print("Select column: 1 - 9: ");
int col = (input.nextInt()-1);
seatChoice = seating[row][col];
if(seatChoice.equals("[XX]"))
{
System.out.println("\n---This seat is already taken---");
System.out.println("---Please select another\n");
businessClass();
}
else if (seatChoice != "[XX]")
{
seating[row][col] = "[XX]";
System.out.println("\nYou have selected seat: " + seatChoice);
seatLayout(seating);
}
section = "Business Class";
boardingPass();
break;
case 2: //case 2 for seat assignment
outerLoop: for (int i = 2; i < 5 ; i++)
{
for (int j = 0; j < 8; j++)
{
if(!(seating[i][j].equals("[XX]")))//test to find available seat, and assign the next available
{
seatChoice = seating[i][j];
seating[i][j] = "[XX]";
break outerLoop;
}
if(seating[5][8].equals("[XX]"))//test to find if all seats are occupied and allow user to move if required
{
System.out.println("All Business seats are full. If you would like a seat in: "
+ "\nFirst class press 1."
+ "\nEconomy press 2. "
+ "\nElse press 3: ");
String choice = input.next();
if(choice.equals("1"))
{
firstClass();
}
else if(choice.equals("2"))
{
economyClass();
}
else
System.out.println("All seats are booked. The next flight is in 6 hours.");
System.exit(0);
}
}
System.out.println();
}
section = "Business Class";
boardingPass();
break;
default:
System.out.println("Invalid input. Please try again.");
businessClass();
break;
}
}
//method for choosing seats in economy
public static void economyClass()
{
System.out.println("Please select how you would like to be seated:"
+ "\nPress 1 to select your own seat."
+ "\nPress 2 to have a seat assigned for you.");
int seatMenu = input.nextInt();
switch (seatMenu)
{
case 1: //case 1 for user self selection
System.out.println("\nPlease select where you would like to sit:\n");
System.out.println("Seat maked [XX] are already taken.\n");
seatLayout(seating);
System.out.print("\nSelect row 6 - 10: ");
int row = (input.nextInt()-1);
System.out.print("Select column: 1 - 9: ");
int col = (input.nextInt()-1);
seatChoice = seating[row][col];
if(seatChoice.equals("[XX]"))
{
System.out.println("\n---This seat is already taken---");
System.out.println("---Please select another\n");
economyClass();
}
else if (seatChoice != "[XX]")
{
seating[row][col] = "[XX]";
System.out.println("\nYou have selected seat: " + seatChoice);
seatLayout(seating);
}
section = "Economy Class";
boardingPass();
break;
case 2: //case 2 for seat assignment
outerLoop: for (int i = 5; i < 9; i++)
{
for (int j = 0; j < 8; j++)
{
if(!(seating[i][j].equals("[XX]")))//test to find available seat, and assign the next available seat
{
seatChoice = seating[i][j];
seating[i][j] = "[XX]";
break outerLoop;
}
if(seating[9][8].equals("[XX]"))//test to find if all seats are occupied and allow user to move if required
{
System.out.println("All Economy seats are full. if you would like a seat in: "
+ "\nFirst class press 1."
+ "\nBusiness press 2. "
+ "\nElse press 3: ");
String choice = input.next();
if(choice.equals("1"))
{
firstClass();
}
else if(choice.equals("2"))
{
businessClass();
}
else
System.out.println("All seats are booked. The next flight is in 6 hours.");
System.exit(0);
}
}
System.out.println();
}
section = "Business Class";
boardingPass();
break;
default:
System.out.println("Invalid input. Please try again.");
economyClass();
break;
}
}
//display the boarding pass with relevant information
public static void boardingPass()
{
String custName = String.format("Name \t\t: %s", name);
String custDepart = String.format("Departure \t: %s", depart);
String custDest = String.format("Destination \t: %s", dest);
String custFlight = String.format("Fligth Number \t: FL%s", flightNum);
String custSeat = String.format("Seat Number \t: %s", seatChoice);
String custSection = String.format("Seat Section \t: %s", section);
System.out.println("\n\t-----BOARDING PASS-----");
System.out.println();
System.out.println(custName);
System.out.println(custDepart);
System.out.println(custDest);
System.out.println(custFlight);
System.out.println(custSeat);
System.out.println(custSection);
System.out.println();
System.out.println("\t-----BOARDING PASS-----");
System.out.println();
seatLayout(seating);
System.out.println();
bookMore();
}
//method to allow user to continue or exit the program
public static void bookMore()
{
System.out.println("Would you like to book more seats? Y/N?");
String choice = input.next();
if (choice.equals("y"))
{
seatPlan();
} else
{
System.out.println("Good Bye");
System.exit(0);
}
}
}
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