Commit f576a4a9 authored by Daniel's avatar Daniel

just need to add comments

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>Coursework_assignment1</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 java.util.Random;
public class Flight_sorter {
static Scanner input = new Scanner(System.in);
//
static int seat, x, y, count = 0, differ, flightno;
//
static String name, origin, destination, section;
//
static String fcseats[][] = {{"01", "XX", "03", "04", "05", "XX", "07", "XX", "09"},
{"XX", "11", "12", "13", "14", "15", "16", "17", "18"}};
//
static String bcseats[][] = {{"XX", "XX", "XX", "XX", "XX", "XX", "XX", "XX", "XX"},
{"XX", "XX", "XX", "XX", "XX", "XX", "XX", "XX", "XX"},
{"XX", "XX", "XX", "XX", "XX", "XX", "XX", "XX", "XX"}};
//
static String ecseats[][] = {{"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"}};
//
public static void main(String[] args) {
System.out.print("Please enter your name: --> ");
name = input.nextLine();
System.out.print("==================================\n");
//Gets the customers name for the boarding pass
System.out.print("Please enter your origin city: --> ");
origin = input.nextLine();
System.out.print("==================================\n");
//Gets the city the customer is flying from
System.out.print("Please enter your destination city: --> ");
destination = input.nextLine();
//Gets the city the customer is flying to
System.out.print("==================================\n");
Random rGen = new Random();
int randInt = rGen.nextInt(28) + 1;
flightno = randInt;
//
//Generates a random number between 1 and 28 for the flight number
if (randInt >= 10) {
System.out.print("Your flight number is FL" + flightno);
}
//
else {
System.out.print("Your flight number is FL0" + flightno);
}
//
System.out.print("\n==================================\n"
+ "Seating Map\n\n");
//Displays the flight number
classes();
//
}
public static void classes() {
int choice;
for(int i=0; i<=1; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + fcseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + fcseats[i][j] + "]");
//
}
}
System.out.println();
}
System.out.println();
for(int i=0; i<=2; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + bcseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + bcseats[i][j] + "]");
//
}
}
System.out.println();
}
System.out.println();
for(int i=0; i<=4; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + ecseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + ecseats[i][j] + "]");
//
}
}
System.out.println();
}
System.out.print("\n==================================");
while(true) {
System.out.print("\nPlease select your travel class:\n"
+ "==================================\n"
+ " Type 1 for First class (01-18) \n"
+ " Type 2 for Business class (19-45) \n"
+ " Type 3 for Economy class (46-90) \n"
+ "==================================\n"
+ "Enter choice here: --> ");
//
choice = input.nextInt();
switch(choice) {
case 1:
section = "First Class";
fclass();
break;
case 2:
section = "Business Class";
bclass();
break;
case 3:
section = "Economy Class";
eclass();
break;
default:
System.out.println();
System.out.print("Please enter a valid value\n\n");
classes();
break;
//
}
break;
}
}
public static void fclass() {
for(int i=0; i<=1; i++) {
for(int j=0; j<=8; j++) {
//
if (fcseats[i][j] != "XX"){
count++;
//
}
}
}
System.out.print("==================================");
if (0 == count) {
System.out.println();
System.out.print("Sorry, First class is full\n"
+ "Would you like to change section?\n"
+ "Type '1' for yes, otherwise type '2' for no --> ");
//
differ = input.nextInt();
if (differ == 1) {
classes();
//
return;
}
else {
System.out.print("==================================");
System.out.print("\nSorry there is no available seat at the moment.\n"
+ "The next flight will leave in 6 hours");
//
return;
}
}
else {
count = 0;
System.out.println();
System.out.println("You have selected First class");
System.out.print("Please select a seat in the region of 1-18 --> ");
//
seat = input.nextInt();
if (seat <= 18 && 0 < seat) {
System.out.print("==========================\n"
+ "checking seat availability\n"
+ "==========================\n");
//
seating();
}
else {
System.out.println();
System.out.print("Please enter a valid seat for this class\n");
fclass();
//
}
}
}
public static void bclass() {
for(int i=0; i<=2; i++) {
for(int j=0; j<=8; j++) {
//
if (bcseats[i][j] != "XX"){
count++;
//
}
}
}
System.out.print("==================================");
if (0 == count) {
//
System.out.println();
System.out.print("Sorry, Business class is full\n"
+ "Would you like to change section?\n"
+ "Type '1' for yes, otherwise type '2' for no --> ");
//
differ = input.nextInt();
if (differ == 1) {
classes();
//
return;
}
else {
System.out.print("==================================");
System.out.print("\nSorry there is no available seat at the moment.\n"
+ "The next flight will leave in 6 hours");
//
return;
}
}
System.out.println();
System.out.println("You have selected Business class");
System.out.print("Please select a seat in the region of 19-45 --> ");
seat = input.nextInt();
//
if (seat <= 45 && 18 < seat) {
System.out.print("==========================\n"
+ "checking seat availability\n"
+ "==========================\n");
//
seating();
}
else {
System.out.println();
System.out.print("Please enter a valid seat for this class\n");
bclass();
//
}
}
public static void eclass() {
for(int i=0; i<=4; i++) {
for(int j=0; j<=8; j++) {
//
if (ecseats[i][j] != "XX"){
count++;
//
}
}
}
System.out.print("==================================");
if (0 == count) {
//
System.out.println();
System.out.print("Sorry, Economy class is full\n"
+ "Would you like to change section?\n"
+ "Type '1' for yes, otherwise type '2' for no --> ");
differ = input.nextInt();
//
if (differ == 1) {
classes();
//
return;
}
else {
System.out.print("==================================");
System.out.print("\nSorry there is no available seat at the moment.\n"
+ "The next flight will leave in 6 hours");
//
return;
}
}
System.out.println();
System.out.println("You have selected Economy class");
System.out.print("Please select a seat in the region of 46-90 --> ");
seat = input.nextInt();
//
if (seat <= 90 && 45 < seat) {
System.out.print("==========================\n"
+ "checking seat availability\n"
+ "==========================\n");
//
seating();
}
else {
System.out.println();
System.out.print("Please enter a valid seat for this class\n");
//
eclass();
}
}
public static void seating() {
y = (seat-1);
//
if (seat <= 18 && 0 < seat) {
//
if (y <=8) {
x = 0;
}
else{
y = y-9;
x = 1;
}
//
if (!(fcseats[x][y].equals("XX"))) {
System.out.print("That seat is available\n\n");
fcseats[x][y] = "XX";
//
}
else if (fcseats[x][y].equals("XX")) {
System.out.print("Sorry, that seat is taken, "
+ "please choose another seat\n");
//
if (seat <= 18 && 0 < seat) {
fclass();
//
return;
}
else if (seat <= 45 && 18 < seat) {
bclass();
//
return;
}
else if (seat <= 90 && 45 < seat) {
eclass();
//
return;
}
}
for(int i=0; i<=1; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + fcseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + fcseats[i][j] + "]");
//
}
}
System.out.println();
}
System.out.println();
for(int i=0; i<=2; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + bcseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + bcseats[i][j] + "]");
//
}
}
System.out.println();
}
System.out.println();
for(int i=0; i<=4; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + ecseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + ecseats[i][j] + "]");
//
}
}
System.out.println();
}
}
else if (seat <= 45 && 18 < seat) {
//
if (y <=26) {
y = y-18;
x = 0;
}
else if (y <=35){
y = y-27;
x = 1;
}
else {
y = y-36;
x = 2;
}
//
if (!(bcseats[x][y].equals("XX"))) {
System.out.print("That seat is available\n\n");
bcseats[x][y] = "XX";
}
//
else if (bcseats[x][y].equals("XX")) {
System.out.print("Sorry, that seat is taken, "
+ "please choose another seat\n");
//
if (seat <= 18 && 0 < seat) {
fclass();
//
return;
}
else if (seat <= 45 && 18 < seat) {
bclass();
//
return;
}
else if (seat <= 90 && 45 < seat) {
eclass();
//
return;
}
}
for(int i=0; i<=1; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + fcseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + fcseats[i][j] + "]");
//
}
}
System.out.println();
}
System.out.println();
for(int i=0; i<=2; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + bcseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + bcseats[i][j] + "]");
//
}
}
System.out.println();
}
System.out.println();
for(int i=0; i<=4; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + ecseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + ecseats[i][j] + "]");
//
}
}
System.out.println();
}
}
if (seat <= 90 && 45 < seat) {
if (y <=53) {
y = y-45;
x = 0;
}
else if (y <=62){
y = y-54;
x = 1;
}
else if (y <=71){
y = y-63;
x = 1;
}
else if (y <=80){
y = y-72;
x = 1;
}
else{
y = y-81;
x = 1;
}
//
if (!(ecseats[x][y].equals("XX"))) {
System.out.print("That seat is available\n\n");
ecseats[x][y] = "XX";
}
//
else if (ecseats[x][y].equals("XX")) {
System.out.print("Sorry, that seat is taken, "
+ "please choose another seat\n");
//
if (seat <= 18 && 0 < seat) {
fclass();
//
return;
}
else if (seat <= 45 && 18 < seat) {
bclass();
//
return;
}
else if (seat <= 90 && 45 < seat) {
eclass();
//
return;
}
}
for(int i=0; i<=1; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + fcseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + fcseats[i][j] + "]");
//
}
}
System.out.println();
}
System.out.println();
for(int i=0; i<=2; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + bcseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + bcseats[i][j] + "]");
//
}
}
System.out.println();
}
System.out.println();
for(int i=0; i<=4; i++) {
for(int j=0; j<=8; j++) {
//
if ((j+1) % 3 == 0) {
System.out.print("[" + ecseats[i][j] +"]" + " ");
//
}
else {
System.out.print("[" + ecseats[i][j] + "]");
//
}
}
System.out.println();
}
}
pass();
}
public static void pass() {
System.out.print("=========================================="
+ " \n|[ BOARDING PASS ]|\n"
+ " NAME : " + name.toUpperCase() + "\n"
+ " FROM : " + origin.toUpperCase() + "\n"
+ " TO : " + destination.toUpperCase() + "\n");
if (flightno >= 10) {
System.out.print(" FLIGHT No : FL" + flightno + "\n");
}
else {
System.out.print(" FLIGHT No : FL0" + flightno + "\n");
}
System.out.print(" SEAT No : " + seat + "\n"
+ " SECTION : " + section.toUpperCase() + "\n"
+ "==========================================\n\n"
+ "Enjoy your flight!");
//
return;
}
}
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