This repository has been archived by the owner on Oct 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bus.java
62 lines (51 loc) · 1.55 KB
/
Bus.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
58
59
60
61
62
public class Bus {
private String busNumber;
private int totalSeats;
private String startingPoint;
private String endingPoint;
private String startingTime;
private double fare;
private boolean[] seats;
public Bus(String busNumber, int totalSeats, String startingPoint, String endingPoint, String startingTime, double fare) {
this.busNumber = busNumber;
this.totalSeats = totalSeats;
this.startingPoint = startingPoint;
this.endingPoint = endingPoint;
this.startingTime = startingTime;
this.fare = fare;
this.seats = new boolean[totalSeats];
}
public String getBusNumber() {
return busNumber;
}
public int getTotalSeats() {
return totalSeats;
}
public String getStartingPoint() {
return startingPoint;
}
public String getEndingPoint() {
return endingPoint;
}
public String getStartingTime() {
return startingTime;
}
public double getFare() {
return fare;
}
public boolean isSeatAvailable(int seatNumber) {
return !seats[seatNumber - 1];
}
public void bookSeat(int seatNumber) {
seats[seatNumber - 1] = true;
}
public void cancelSeat(int seatNumber) {
seats[seatNumber - 1] = false;
}
public void showSeatingPlan() {
for (int i = 0; i < seats.length; i++) {
System.out.print((seats[i] ? "X" : "O") + " ");
}
System.out.println();
}
}