-
Notifications
You must be signed in to change notification settings - Fork 0
/
Flight.java
executable file
·49 lines (40 loc) · 1.26 KB
/
Flight.java
1
2
3
4
5
6
7
8
9
10
11
12
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
46
47
48
49
import java.util.Vector;
public class Flight {
// variables initialization
private static int flightIdCounter = 0;
private int flight_id;
private String fDestination;
private int fCapacity;
public Vector<Seat> seats = new Vector<Seat>();
// this block of code runs always when we create a new object of this class
{
flightIdCounter++; // increment flightIdCounter by 1
flight_id = flightIdCounter; // set flight_id equal to flightIdCounter so that the id value is preserved
}
// constructor
public Flight(String fdestination, int capacity) {
this.fDestination = fdestination; // set Flight name (fdestination) = fdestination
this.fCapacity = capacity; // set flight capacity = fCapacity
for (int i = 1; i < capacity+1; i++){
Seat seat = new Seat(flight_id, false, fdestination);
seats.add(seat);
}
}
// get fDestination
public String flightDestination() {
return fDestination;
}
// flightID getter
public int flightId(){
return flight_id;
}
// capacity getter
public int getCapacity(){
return fCapacity;
}
///////////// Override ////////// format the printout of this object
@Override
public String toString(){
return String.format(" %s\t| %s \t|\t%s\t|", flight_id, fDestination, fCapacity);
}
}