-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrain.java
50 lines (41 loc) · 1.5 KB
/
Train.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
public class Train{
private int nToSeats; //posti
private int nFirstClassSeats; //posti
private int nSecondClassSeats; //posti
private int nFirstClassReservedSeats; //posti presi
private int nSecondClassReservedSeats; //posti preso
public void build(int first, int second){
this.nFirstClassSeats = first;
this.nSecondClassSeats = second;
this.nToSeats = this.nFirstClassSeats + this.nSecondClassSeats;
this.nFirstClassReservedSeats = 0;
this.nSecondClassReservedSeats = 0;
}
public void reserveFirstClassSeats(int n){
if((this.nFirstClassReservedSeats + n) < this.nFirstClassSeats){
this.nFirstClassReservedSeats += n;
}else{
System.out.println("Posti insufficenti in prima classe");
}
}
public void reserveSecondClassSeats(int n){
if((this.nSecondClassReservedSeats + n) < this.nSecondClassSeats ){
this.nSecondClassReservedSeats += n;
}else{
System.out.println("Posti insufficenti in prima classe");
}
}
public double getToOccupancyRatio(){
return ((double)(this.nFirstClassReservedSeats + this.nSecondClassReservedSeats) / this.nToSeats)*100;
}
public double getFirstClassOccupancyRatio(){
return ((double)this.nFirstClassReservedSeats / this.nFirstClassSeats)*100;
}
public double getSecondClassOccupancyRatio(){
return ((double)this.nSecondClassReservedSeats / this.nSecondClassSeats)*100;
}
public void deleteAllReservations(){
this.nFirstClassReservedSeats = 0;
this.nSecondClassReservedSeats = 0;
}
}