Commit 26aeab05 authored by jonathan.craske's avatar jonathan.craske

l

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>flightbooking</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
package flightbooking;
import java.util.Scanner;
public class flightbooking {
public static Scanner input = new Scanner(System.in);
public static int userInput;
public static String selectSeat;
public static boolean seatTaken = false;
public static String name;
public static String originDestination;
public static String destination;
public static int flightNum = 01;
public static String[][] first_class = new String [9][2];
public static String[][] business_class = new String[9][3];
public static String[][] economy_class = new String[9][5];
public static int numberAssigner = 1;
public static void main(String[] args)
{
populateSeatNum(first_class);
populateSeatNum(business_class);
populateSeatNum(economy_class);
menuChoice();
}
//function for generating boarding pass
public static void boardingPass()
{
System.out.println("|[ BOARDING PASS ]|");
System.out.println("Name :" + name );
System.out.println("From :" + originDestination);
System.out.println("Destination :" + destination);
System.out.println("Flight :" + flightNum);
System.out.println("Seat No :" + selectSeat);
System.out.println("Section :FL" + flightNum);
flightNum++;
}
//function to assign a seat
public static void chooseSeat(String[][] seats)
{
System.out.println("Enter seat you wish to book > ");
selectSeat = input.next();
for (int i = 0; i < seats[0].length; i++)
{
if(seatTaken == true)
{
break;
}
for (int j = 0; j < seats.length; j++)
{
// assigns seat if it is free
if (selectSeat.equals(seats[j][i]))
{
seats[j][i] = "XX";
seatTaken = true;
if(seatTaken == true)
{
System.out.println("Seat " + selectSeat + " booked");
boardingPass();
break;
}
classAssigner(seats);
}
}
}
}
// function for menu choices
public static void menuChoice()
{
//menu for classes
System.out.println("Please enter name > " );
name = input.next();
System.out.println("City of Origin > ");
originDestination = input.next();
System.out.println("Destination travelling to > ");
destination = input.next();
System.out.println("please choose which class you would like,\n"
+ "1 for first class,\n"
+ "2 for business class, \n"
+ "3 for economy class, \n ");
int customerChoice = input.nextInt();
switch(customerChoice)
{
case 1:
classAssigner(first_class);
break;
case 2:
classAssigner(business_class);
break;
case 3:
classAssigner(economy_class);
break;
}
}
// assign and create seat charts for each class
public static void classAssigner(String[][]assignClass)
{
int counter = 1;
for(int column =0; column < assignClass[0].length; column++)
{
counter = 1;
for(int row=0; row < assignClass.length; row++)
{
if(counter > 3)
{
System.out.print(" " + "[" + assignClass[row][column] + "]" + "" );
counter =1;
}
else
{
System.out.print("[" + assignClass[row][column] + "]" + "" );
}
counter++;
}
System.out.println();
}
chooseSeat(assignClass);
}
//Initialize 2-D array which is called seatClass
public static void populateSeatNum(String[][]seatAssign)
{
for(int column =0; column < seatAssign[0].length; column++)
{
for(int row=0; row < seatAssign.length; row++)
{
seatAssign[row][column] = Integer.toString(numberAssigner);
numberAssigner++;
}
}
}
}
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