-
Notifications
You must be signed in to change notification settings - Fork 0
/
Seat.java
executable file
·57 lines (46 loc) · 1.16 KB
/
Seat.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
50
51
52
53
54
55
56
57
public class Seat {
private static int seatIdCounter = 0;
private int seat_id;
private int flight_id;
private boolean isBooked;
private String fDestination;
{
seatIdCounter++; // increment seat_id by 1
seat_id = seatIdCounter; // set seat_id equal to seatIdCounter;
}
// constructor
public Seat(int fID, boolean isbooked, String destination){
this.flight_id = fID;
this.isBooked = isbooked;
this.fDestination = destination;
}
// get seat ID
public int seatId(){
return seat_id;
}
// get flight ID
public int flightId(){
return flight_id;
}
//get flight destination
public String fDestination(){
return fDestination;
}
// check if seat is booked
public boolean isBooked() {
return isBooked;
}
// book the seat
public void bookSeat() {
if(!this.isBooked){
this.isBooked = true;
}else {
System.out.println("Seat "+ this.seat_id +" is already booked!!!");
}
}
///////////// Override ////////// format the printout of this object
@Override
public String toString(){
return String.format("%2s\t|%4s\t|%12s\t|%8s |", this.seat_id, this.flight_id, this.fDestination, this.isBooked);
}
}