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
ryan.whiteley
AirlineReservation
Commits
7bbc3ed6
Commit
7bbc3ed6
authored
Nov 03, 2019
by
ryanw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assignment upload
parents
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
441 additions
and
0 deletions
+441
-0
.classpath
.classpath
+6
-0
.gitignore
.gitignore
+1
-0
.project
.project
+17
-0
Airoplane_Seat_System.java
src/Airoplane_Seat_System.java
+417
-0
No files found.
.classpath
0 → 100644
View file @
7bbc3ed6
<?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>
.gitignore
0 → 100644
View file @
7bbc3ed6
/bin/
.project
0 → 100644
View file @
7bbc3ed6
<?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>
src/Airoplane_Seat_System.java
0 → 100644
View file @
7bbc3ed6
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
);
}
}
}
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