-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassager.java
More file actions
74 lines (59 loc) · 2.06 KB
/
Passager.java
File metadata and controls
74 lines (59 loc) · 2.06 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
public class Passager {
/* Dans cette classe, vous pouvez ajouter/enlever/modifier/corriger des méthodes, mais vous ne
pouvez pas ajouter des attributs (variables d'instance).
Quand vous serez en mode recherche de vitesse, vous pourrez tout faire, ici et ailleurs.
*/
public long numéroDeCréation;
private long dateDépart;
private Etage étageDépart;
private Etage étageDestination;
public long dateDépart() {
return this.dateDépart;
}
public Etage étageDépart() {
return this.étageDépart;
}
public int numéroDepart() {
return this.étageDépart.numéro();
}
public Etage étageDestination() {
return this.étageDestination;
}
public int numéroDestination() {
return this.étageDestination.numéro();
}
public Passager(long dateDeDepart, Etage etageDeDepart, Immeuble immeuble) {
Etage niveauDuSol = immeuble.niveauDuSol();
int nbEtages = immeuble.nbEtages();
étageDépart = etageDeDepart;
dateDépart = dateDeDepart;
compteurGlobalDeCreationDesPassagers++;
numéroDeCréation = compteurGlobalDeCreationDesPassagers;
if (étageDépart == niveauDuSol) {
étageDestination = niveauDuSol;
while (étageDestination == niveauDuSol) {
int auPif = randomGenerator.intSuivant(nbEtages);
étageDestination = immeuble.étage(auPif + immeuble.étageLePlusBas().numéro() - 1);
}
} else {
étageDestination = niveauDuSol;
}
}
private static int compteurGlobalDeCreationDesPassagers = 0;
private static final PressRandomNumberGenerator randomGenerator = new PressRandomNumberGenerator(34);
public char sens () {
return (étageDestination.numéro() > étageDépart.numéro() ? '^' : 'v');
}
public void afficheDans(StringBuilder buffer) {
int depa = étageDépart.numéro();
int dest = étageDestination.numéro();
buffer.append('#');
buffer.append(numéroDeCréation);
buffer.append(':');
buffer.append(depa);
buffer.append(dest > depa ? '^' : 'v');
buffer.append(dest);
buffer.append(':');
buffer.append(dateDépart);
}
}