Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AirlineReservation
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
daniel.berrow
AirlineReservation
Commits
06abb155
Commit
06abb155
authored
Oct 30, 2019
by
Daniel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final
parents
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
572 additions
and
0 deletions
+572
-0
airlineReservationProgram.java
airlineReservationProgram.java
+572
-0
No files found.
airlineReservationProgram.java
0 → 100644
View file @
06abb155
import
java.util.Scanner
;
import
java.util.Random
;
public
class
airlineReservationProgram
{
static
Scanner
input
=
new
Scanner
(
System
.
in
);
//Creates the scanner for inputting values
static
int
seat
,
x
,
y
,
count
=
0
,
differ
,
flightno
;
//defines my integer variables that were required in the program
static
String
name
,
origin
,
destination
,
section
;
//defines my string variables that were required in the program
static
String
fcseats
[][]
=
{{
"01"
,
"XX"
,
"03"
,
"04"
,
"05"
,
"XX"
,
"07"
,
"XX"
,
"09"
},
{
"XX"
,
"11"
,
"12"
,
"13"
,
"14"
,
"15"
,
"16"
,
"17"
,
"18"
}};
//creates an array for the seats in first class
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"
}};
//creates an array for the seats in business class
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"
}};
//creates an array for the seats in economy class
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
);
}
//displays the flight number for when the flight number is higher than 10
else
{
System
.
out
.
print
(
"Your flight number is FL0"
+
flightno
);
}
//displays the flight number for when the flight number is lower than 10
System
.
out
.
print
(
"\n==================================\n"
+
"Seating Map\n\n"
);
//Displays the flight number
classes
();
//goes to the classes selection function
}
public
static
void
classes
()
{
int
choice
;
for
(
int
i
=
0
;
i
<=
1
;
i
++)
{
for
(
int
j
=
0
;
j
<=
8
;
j
++)
{
//nested for loop to read along the array for its dimensions
if
((
j
+
1
)
%
3
==
0
)
{
System
.
out
.
print
(
"["
+
fcseats
[
i
][
j
]
+
"]"
+
" "
);
//every 3rd element has a gap with it to make room for the aisle when the plan is displayed
}
else
{
System
.
out
.
print
(
"["
+
fcseats
[
i
][
j
]
+
"]"
);
//prints out the other elements to be displayed in the plan
}
}
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
]
+
"]"
);
//repeats the process but for business class instead of first class
}
}
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
]
+
"]"
);
//repeats the process but for economy class instead of first class
}
}
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: --> "
);
//displays the 3 choices to be made for which class the customer is selecting
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
;
//the outcome of each of the choices, each choice takes the customer to the respective function for that choice
}
break
;
}
}
public
static
void
fclass
()
{
for
(
int
i
=
0
;
i
<=
1
;
i
++)
{
for
(
int
j
=
0
;
j
<=
8
;
j
++)
{
//loops through the array to check each element
if
(
fcseats
[
i
][
j
]
!=
"XX"
){
count
++;
//if the element within the array is not "XX" then the counter increases
}
}
}
System
.
out
.
print
(
"=================================="
);
if
(
0
==
count
)
{
//if the counter doesn't increase and remains at 0 then it means that the class is full
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 --> "
);
//gives an option to change class or to not book the flight
differ
=
input
.
nextInt
();
if
(
differ
==
1
)
{
classes
();
//if they choose to change section then go back to the class selection function
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"
);
//if they choose the not be on that flight then display there is 6 hours to next flight and end program
return
;
}
}
else
{
count
=
0
;
//resets count in case they end up back at class selection system again in which case count will need to set at 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 --> "
);
//displays that the class they have chosen has room and also shows what range of seats are in the class
seat
=
input
.
nextInt
();
if
(
seat
<=
18
&&
0
<
seat
)
{
System
.
out
.
print
(
"==========================\n"
+
"checking seat availability\n"
+
"==========================\n"
);
seating
();
//goes to the seating function
}
else
{
System
.
out
.
println
();
System
.
out
.
print
(
"Please enter a valid seat for this class\n"
);
fclass
();
//an invalid seat was chosen so they have another chance to choose a valid seat
}
}
}
public
static
void
bclass
()
{
for
(
int
i
=
0
;
i
<=
2
;
i
++)
{
for
(
int
j
=
0
;
j
<=
8
;
j
++)
{
//goes through the business class array
if
(
bcseats
[
i
][
j
]
!=
"XX"
){
count
++;
//if the counter doesn't increase and remains at 0 then it means that the class is full
}
}
}
System
.
out
.
print
(
"=================================="
);
if
(
0
==
count
)
{
//if the count is 0 then the class is full
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
();
//if they wish to remain on same flight then they choose to change class
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"
);
//displays next flight is in 6 hours and program ends
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
();
//displays the range of seats they can select from in business class
if
(
seat
<=
45
&&
18
<
seat
)
{
System
.
out
.
print
(
"==========================\n"
+
"checking seat availability\n"
+
"==========================\n"
);
seating
();
//goes to the seating function
}
else
{
System
.
out
.
println
();
System
.
out
.
print
(
"Please enter a valid seat for this class\n"
);
bclass
();
//the value they chose is out of the range so goes back to the seat selection for business class
}
}
public
static
void
eclass
()
{
for
(
int
i
=
0
;
i
<=
4
;
i
++)
{
for
(
int
j
=
0
;
j
<=
8
;
j
++)
{
if
(
ecseats
[
i
][
j
]
!=
"XX"
){
count
++;
//if the counter doesn't increase and remains at 0 then it means that the class is full
}
}
}
System
.
out
.
print
(
"=================================="
);
if
(
0
==
count
)
{
//since the counter is 0 the economy class is full
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
();
//gives the option whether to change class or to not take this flight
if
(
differ
==
1
)
{
classes
();
//go back to the choice where they pick their class
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"
);
//displays that there is 6 hours to the next flight
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
();
//shows the range of seats available within the economy class
if
(
seat
<=
90
&&
45
<
seat
)
{
System
.
out
.
print
(
"==========================\n"
+
"checking seat availability\n"
+
"==========================\n"
);
//goes to the seating function
seating
();
}
else
{
System
.
out
.
println
();
System
.
out
.
print
(
"Please enter a valid seat for this class\n"
);
//value entered was out of the range for the value in the economy section
eclass
();
}
}
public
static
void
seating
()
{
y
=
(
seat
-
1
);
//sets y to be used as an index, as the first element of an array is 0, not 1
if
(
seat
<=
18
&&
0
<
seat
)
{
//if seat is within this range then the customer is in first class
if
(
y
<=
8
)
{
x
=
0
;
}
else
{
y
=
y
-
9
;
x
=
1
;
}
//adjusts y to be in range 0-8 for each row of seats
if
(!(
fcseats
[
x
][
y
].
equals
(
"XX"
)))
{
System
.
out
.
print
(
"That seat is available\n\n"
);
fcseats
[
x
][
y
]
=
"XX"
;
//checks if the seat chosen is not taken, and then changes it to show that the seat is now taken
}
else
if
(
fcseats
[
x
][
y
].
equals
(
"XX"
))
{
System
.
out
.
print
(
"Sorry, that seat is taken, "
+
"please choose another seat\n"
);
//checks if the seat is taken, and then displays that the seat was already taken so a different seat is required to be selected
if
(
seat
<=
18
&&
0
<
seat
)
{
fclass
();
//goes back to the appropriate class
return
;
}
else
if
(
seat
<=
45
&&
18
<
seat
)
{
bclass
();
//goes back to the appropriate class
return
;
}
else
if
(
seat
<=
90
&&
45
<
seat
)
{
eclass
();
//goes back to the appropriate class
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
]
+
"]"
);
}
//displays the seating plan again with the selected seat showed
}
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
]
+
"]"
);
//displays the seating plan again with the selected seat showed
}
}
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
();
//displays the seating plan again with the selected seat showed
}
}
else
if
(
seat
<=
45
&&
18
<
seat
)
{
//the seating range of business class
if
(
y
<=
26
)
{
y
=
y
-
18
;
x
=
0
;
}
else
if
(
y
<=
35
){
y
=
y
-
27
;
x
=
1
;
}
else
{
y
=
y
-
36
;
x
=
2
;
}
//keeps the range of y, the index, for 0-8
if
(!(
bcseats
[
x
][
y
].
equals
(
"XX"
)))
{
System
.
out
.
print
(
"That seat is available\n\n"
);
bcseats
[
x
][
y
]
=
"XX"
;
}
//checks that the seat is available, and then changes the value to show it has been taken by the customer
else
if
(
bcseats
[
x
][
y
].
equals
(
"XX"
))
{
System
.
out
.
print
(
"Sorry, that seat is taken, "
+
"please choose another seat\n"
);
//checks if the seat is available, and if it is then it displays that the seat is taken so choose a different seat
if
(
seat
<=
18
&&
0
<
seat
)
{
fclass
();
//goes back to the appropriate class if seat taken
return
;
}
else
if
(
seat
<=
45
&&
18
<
seat
)
{
bclass
();
//goes back to the appropriate class if seat taken
return
;
}
else
if
(
seat
<=
90
&&
45
<
seat
)
{
eclass
();
//goes back to the appropriate class if seat taken
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
]
+
"]"
);
}
}
//displays the seating plan again with the selected seat showed
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
();
//displays the seating plan again with the selected seat showed
}
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
();
//displays the seating plan again with the selected seat showed
}
}
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
=
2
;
}
else
if
(
y
<=
80
){
y
=
y
-
72
;
x
=
3
;
}
else
{
y
=
y
-
81
;
x
=
4
;
}
//keeps the index, y, in the range 0-8 for the array
if
(!(
ecseats
[
x
][
y
].
equals
(
"XX"
)))
{
System
.
out
.
print
(
"That seat is available\n\n"
);
ecseats
[
x
][
y
]
=
"XX"
;
}
//checks that the seat is available, and if it is then it displays that the seat has been taken by the customer
else
if
(
ecseats
[
x
][
y
].
equals
(
"XX"
))
{
System
.
out
.
print
(
"Sorry, that seat is taken, "
+
"please choose another seat\n"
);
//if the seat is already taken then it tells the customer the seat is already taken
if
(
seat
<=
18
&&
0
<
seat
)
{
fclass
();
//goes back to the appropriate seat choice class
return
;
}
else
if
(
seat
<=
45
&&
18
<
seat
)
{
bclass
();
//goes back to the appropriate seat choice class
return
;
}
else
if
(
seat
<=
90
&&
45
<
seat
)
{
eclass
();
//goes back to the appropriate seat choice class
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
]
+
"]"
);
}
}
//displays the seating plan again with the selected seat showed
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
]
+
"]"
);
}
}
//displays the seating plan again with the selected seat showed
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
]
+
"]"
);
}
}
//displays the seating plan again with the selected seat showed
System
.
out
.
println
();
}
}
pass
();
//goes to the boarding pass printing function
}
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"
);
}
//if the flight number is greater than or eqaul to 10 then it displays only FL prior to the number
else
{
System
.
out
.
print
(
" FLIGHT No : FL0"
+
flightno
+
"\n"
);
}
//if the flight number is less than 10 then it displays FL0 with the flight number added to the end
System
.
out
.
print
(
" SEAT No : "
+
seat
+
"\n"
+
" SECTION : "
+
section
.
toUpperCase
()
+
"\n"
+
"==========================================\n\n"
+
"Enjoy your flight!"
);
//prints out the boarding pass and ends the program
return
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment