-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrainclass.java
58 lines (50 loc) · 1.66 KB
/
Trainclass.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
class Train {
private int trainNumber;
private String trainName;
private String source;
private String destination;
private String departureTime;
private int maxSeats = 50;
private int availableSeats;
public Train(int trainNumber, String trainName, String source, String destination, String departureTime, int maxSeats) {
this.trainNumber = trainNumber;
this.trainName = trainName;
this.source = source;
this.destination = destination;
this.departureTime = departureTime;
this.maxSeats = maxSeats;
this.availableSeats = maxSeats; // Initially, all seats are available
}
public int getTrainNumber() {
return trainNumber;
}
public String getSource() {
return source;
}
public String getDestination() {
return destination;
}
public String getDepartureTime() {
return departureTime;
}
public int getAvailableSeats() {
return availableSeats;
}
public boolean bookSeat() {
if (availableSeats > 0) {
availableSeats--;
return true; // Seat booked successfully
}
return false; // No available seats
}
void print(){
System.out.println("prerana");
}
}
public class Trainclass {
public static void main(String[] args) {
// Use the correct maximum seats value (50 in this case)
Train obj = new Train(1, "Sbp", "burla", "Suiit", "fhsdu", 50);
obj.print();
}
}