Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
lab7-1
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
9731073
lab7-1
Commits
5b990fd0
Commit
5b990fd0
authored
May 05, 2019
by
9731073
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lastcommit
parent
be0f6044
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
314 additions
and
17 deletions
+314
-17
Airplane.java
src/Airplane.java
+60
-3
DateAndTime.java
src/DateAndTime.java
+37
-3
Flight.java
src/Flight.java
+60
-6
Seat.java
src/Seat.java
+28
-1
System.java
src/System.java
+45
-1
Ticket.java
src/Ticket.java
+60
-1
User.java
src/User.java
+24
-2
No files found.
src/Airplane.java
View file @
5b990fd0
import
java.util.ArrayList
;
import
java.util.ArrayList
;
/**
* @author Abtin Aghamirzaei
* this class is airplane class and airplane are collaborated
* with seat and flight classes directly
*/
public
class
Airplane
{
public
class
Airplane
{
String
type
;
String
type
;
int
freeSeatsNumber
;
int
seatsNumber
=
0
;
String
agency
;
/**
* arraylist of the reserved seats in an airplane
*/
ArrayList
<
Seat
>
seats
=
new
ArrayList
<>();
ArrayList
<
Seat
>
seats
=
new
ArrayList
<>();
public
Airplane
(
String
type
)
{
public
Airplane
(
String
type
,
String
agency
,
int
seatsNumber
)
{
this
.
type
=
type
;
this
.
type
=
type
;
this
.
freeSeatsNumber
=
seatsNumber
;
this
.
seatsNumber
=
seatsNumber
;
this
.
agency
=
agency
;
}
}
/**
*
* @return the type of aircraft
*/
public
String
getType
(){
public
String
getType
(){
return
type
;
return
type
;
}
}
public
void
reserveSeat
(
Seat
s
){
/**
seats
.
add
(
s
);
* this methode takes a seat and checks if that seat is already occupied or not
* and if the seat is free it reserves the seat otherwise nothing
* @param seat is the seat which should be checked
* @return if the seat is free it returns false and if the seat is full it returns true
*/
public
boolean
reserveSeat
(
Seat
seat
){
if
(
seats
.
contains
(
seat
))
{
java
.
lang
.
System
.
out
.
println
(
"seat is reserved"
);
return
false
;
}
else
{
seats
.
add
(
seat
);
seatsNumber
++;
return
true
;
}
}
}
/**
*
* @return the airplane's agency (or airline)
*/
public
String
getAgency
()
{
return
agency
;
}
/**
*
* @return all reserved seats in airplane
*/
public
ArrayList
getSeats
(){
return
seats
;
}
/**
*
* @return number of the seats
*/
public
int
getSeatsNumber
(){
return
seatsNumber
;
}
}
}
src/DateAndTime.java
View file @
5b990fd0
/**
* @author Abtin Aghamirzaei
*
* this class manages the time of flight
*/
public
class
DateAndTime
{
public
class
DateAndTime
{
int
day
;
int
day
;
int
hour
;
int
hour
;
int
minute
;
public
DateAndTime
(
int
day
,
int
hour
){
public
DateAndTime
(
int
day
,
int
hour
,
int
minute
){
this
.
day
=
day
;
this
.
day
=
day
;
this
.
hour
=
hour
;
this
.
hour
=
hour
;
this
.
minute
=
minute
;
}
/**
*
* @return the hour of the flight
*/
public
int
getHour
()
{
return
hour
;
}
/**
*
* @return the day of the flight
*/
public
int
getDay
()
{
return
day
;
}
/**
*
* @param hour
* sets hour of the flight
*/
public
void
setHour
(
int
hour
)
{
this
.
hour
=
hour
;
}
/**
*
* @param day
* sets day of the flight
*/
public
void
setDay
(
int
day
)
{
this
.
day
=
day
;
}
}
}
}
src/Flight.java
View file @
5b990fd0
import
java.util.ArrayList
;
import
java.util.ArrayList
;
/**
* @author Abtin Agjamirzaei
*
* flight class represents fields related to flights
*/
public
class
Flight
{
public
class
Flight
{
int
day
;
int
day
;
int
hour
;
int
hour
;
int
minute
;
int
id
;
int
id
;
String
destination
;
String
destination
;
String
source
;
String
source
;
String
company
;
String
company
;
Airplane
airplane
;
Airplane
airplane
;
DateAndTime
dateAndTime
;
DateAndTime
dateAndTime
;
public
Flight
(
int
id
,
String
source
,
String
destination
,
String
company
,
String
airplaneType
,
int
day
,
int
hour
,
int
minute
){
String
type
;
dateAndTime
=
new
DateAndTime
(
day
,
hour
,
minute
);
public
Flight
(
int
id
,
String
source
,
String
destination
,
String
company
,
Airplane
airplane
,
int
day
,
int
hour
){
airplane
=
new
Airplane
(
airplaneType
)
;
this
.
airplane
=
airplane
;
this
.
destination
=
destination
;
this
.
destination
=
destination
;
this
.
source
=
source
;
this
.
source
=
source
;
this
.
company
=
company
;
this
.
company
=
company
;
this
.
id
=
id
;
this
.
id
=
id
;
this
.
day
=
day
;
this
.
hour
=
hour
;
this
.
type
=
airplane
.
getType
();
this
.
company
=
airplane
.
getAgency
();
this
.
dateAndTime
.
setHour
(
hour
);
this
.
dateAndTime
.
setDay
(
day
);
}
}
/**
*
* @return type of the Aircraft
*/
public
String
getType
(){
return
type
;
}
/**
*
* @return flight number
*/
public
int
getId
(){
public
int
getId
(){
return
id
;
return
id
;
}
}
public
String
getDestination
(){
/**
*
* @return destination of the flight
*/
public
String
getDestination
()
{
return
destination
;
return
destination
;
}
}
public
String
getSource
(){
/**
*
* @return source of the flight
*/
public
String
getSource
()
{
return
source
;
return
source
;
}
}
/**
*
* @return airplain's company (airline)
*/
public
String
getCompany
(){
public
String
getCompany
(){
return
company
;
return
company
;
}
}
/**
*
* @return object of airplane
*/
public
Airplane
getAirplane
(){
public
Airplane
getAirplane
(){
return
airplane
;
return
airplane
;
}
}
/**
*
* @return dateandtime of the flight
*/
public
DateAndTime
getDateTime
(){
public
DateAndTime
getDateTime
(){
return
dateAndTime
;
return
dateAndTime
;
}
}
/**
*
* @param flight which is a flight object
* shows details of a specific flight
*/
public
void
show
(
Flight
flight
){
java
.
lang
.
System
.
out
.
println
(
flight
.
getDateTime
());
java
.
lang
.
System
.
out
.
println
(
flight
.
getDestination
());
java
.
lang
.
System
.
out
.
println
(
flight
.
getCompany
());
java
.
lang
.
System
.
out
.
println
(
flight
.
getType
());
java
.
lang
.
System
.
out
.
println
(
flight
.
getId
());
}
}
}
src/Seat.java
View file @
5b990fd0
public
class
Seat
{
public
class
Seat
{
/**
* @author Abtin Aghamirzaei
*
* this class indicates a seat and it's features for us
*/
String
type
;
String
type
;
int
number
;
int
number
;
User
user
;
User
user
;
...
@@ -7,16 +11,39 @@ public class Seat {
...
@@ -7,16 +11,39 @@ public class Seat {
this
.
type
=
type
;
this
.
type
=
type
;
this
.
number
=
number
;
this
.
number
=
number
;
}
}
/**
*
* @return type of the seat which can be business class, first class or economic class
*/
public
String
getType
(){
public
String
getType
(){
return
type
;
return
type
;
}
}
/**
*
* @return seat's number
*/
public
int
getNumber
(){
public
int
getNumber
(){
return
number
;
return
number
;
}
}
/**
*
* @param userId is our user ID who booked the seat and set this ID
*/
public
void
setUser
(
String
userFirstName
,
String
userFamilyName
,
int
userId
){
public
void
setUser
(
String
userFirstName
,
String
userFamilyName
,
int
userId
){
user
=
new
User
(
userFirstName
,
userFamilyName
,
userId
);
user
=
new
User
(
userFirstName
,
userFamilyName
,
userId
);
}
}
/**
*
* @return the user who has reserved the seat
*/
public
User
getUser
(){
public
User
getUser
(){
return
user
;
return
user
;
}
}
/**
*
* @return the ID of the user who has reserved this seat already
*/
public
int
getUserId
(){
return
user
.
getId
();
}
}
}
src/System.java
View file @
5b990fd0
import
java.util.ArrayList
;
/**
* @author Abtin Aghamirzaei
*
* this class manages the booking flights
*/
public
class
System
{
public
class
System
{
ArrayList
<
Flight
>
flights
=
new
ArrayList
<>();
/**
*
* @return flights
*/
public
ArrayList
getFlights
(){
return
flights
;
}
/**
*
* @param flight
* add a flight to our list
*/
public
void
addFlight
(
Flight
flight
){
flights
.
add
(
flight
);
}
/**
*
* @param flight
* removes a flight from our list
*/
public
void
removeFlight
(
Flight
flight
){
flights
.
remove
(
flight
);
}
/**
*
*
* chooses a seat and reserves it for a user
*/
public
void
chooseSeat
(
int
flightNumber
,
int
seatNumber
,
User
user
,
boolean
food
,
int
luggage
/*,Ticket ticket*/
){
Ticket
ticket
=
new
Ticket
(
flightNumber
,
seatNumber
,
luggage
,
food
);
flights
.
get
(
flightNumber
).
getAirplane
().
getSeats
().
get
(
seatNumber
);
for
(
int
i
=
0
;
i
<
flights
.
get
(
flightNumber
).
getAirplane
().
seatsNumber
;
i
++)
{
if
(
seatNumber
==
flights
.
get
(
flightNumber
).
getAirplane
().
seats
.
get
(
i
).
number
){
//flights.get(flightNumber).getAirplane().reserveSeat(flights.get(flightNumber).getAirplane().seats.get(i));
user
.
reserve
(
ticket
,
flights
.
get
(
flightNumber
).
getAirplane
().
seats
.
get
(
i
));
}
}
}
}
}
src/Ticket.java
View file @
5b990fd0
public
class
Ticket
{
/**
* @author Abtin Aghamirzaei
*
* this class is for simulating a ticket
*/
public
class
Ticket
{
int
seatNumber
;
int
flightNumber
;
Boolean
food
;
Seat
seat
;
int
luggage
;
Flight
flight
;
public
Ticket
(
int
flightNumber
,
int
seatNumber
,
int
luggage
,
boolean
food
){
this
.
flightNumber
=
flightNumber
;
this
.
seatNumber
=
seatNumber
;
this
.
food
=
food
;
this
.
luggage
=
luggage
;
}
/**
*
* @return the object of user's seat
*/
public
int
getSeatNumber
(){
return
seatNumber
;
}
/**
*
* @return user's flight number ( which is obviously mentioned in the ticket)
*/
public
int
getFlightNumber
(){
return
flightNumber
;
}
/**
*
* @return user's seat number
*/
public
Seat
getSeat
()
{
return
seat
;
}
/**
* each user can have a meal
* @return if a user wants food or not
*/
public
boolean
getFood
(){
return
food
;
}
/**
*
* @return the flight that user is going to use it
*/
public
Flight
getFlight
()
{
return
flight
;
}
/**
* each user can have a specific amount of luggage
* @return the user's luggage weight
*/
public
int
getLuggage
(){
return
luggage
;
}
}
}
src/User.java
View file @
5b990fd0
import
java.util.ArrayList
;
import
java.util.ArrayList
;
/**
* @author Abtin Aghamirzaei
* this class is our users's class
*/
public
class
User
{
public
class
User
{
String
firstName
;
String
firstName
;
String
lastName
;
String
lastName
;
...
@@ -10,16 +14,34 @@ public class User {
...
@@ -10,16 +14,34 @@ public class User {
this
.
lastName
=
lastName
;
this
.
lastName
=
lastName
;
this
.
id
=
id
;
this
.
id
=
id
;
}
}
/**
*
* @returnour user's first name
*/
public
String
getFirstName
(){
public
String
getFirstName
(){
return
firstName
;
return
firstName
;
}
}
/**
*
* @returnour user's last name
*/
public
String
getLastName
(){
public
String
getLastName
(){
return
lastName
;
return
lastName
;
}
}
/**
*
* @return our user's ID
*/
public
int
getId
(){
public
int
getId
(){
return
id
;
return
id
;
}
}
public
void
reserve
(
Seat
seat
,
Boolean
food
,
int
weight
){
/**
*
* @param ticket which is a ticket that our customer wants to buy
* customer buy the ticket ad the seat will be booked
*/
public
void
reserve
(
Ticket
ticket
,
Seat
seat
){
ticket
.
getFlight
().
getAirplane
().
reserveSeat
(
ticket
.
getSeat
());
tickets
.
add
(
ticket
);
}
}
}
}
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