forked from daveagp/java_visualize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChoix.java
More file actions
60 lines (60 loc) · 1.38 KB
/
Choix.java
File metadata and controls
60 lines (60 loc) · 1.38 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
package studsabstract;
public abstract class Choix {
private Bulletin[] lesBulletins;
int nbBulletinsPour, nbBulletinsContre, indexBulletins;
public Choix() {
lesBulletins = new Bulletin[100];
indexBulletins = 0;
nbBulletinsPour = 0;
nbBulletinsContre = 0;
}
public int addBulletin(Bulletin b) {
lesBulletins[indexBulletins++] = b;
if(b.getValue()){
nbBulletinsPour++ ;
} else {
nbBulletinsContre++ ;
}
return indexBulletins;
}
public int getNbBulletinsPour() {
return nbBulletinsPour;
}
public int getNbBulletinsContre(){
return nbBulletinsContre;
}
public int chercherRang(Bulletin b){
for(int i = 0; i < indexBulletins; i++){
if(b.equals(lesBulletins[i]))return i;
}
return -1;
}
public void retirerBulletin(final Bulletin retrait) {
int rang = chercherRang(retrait);
if(rang > -1){
compacterBulletins(rang);
}
}
public void compacterBulletins(int r){
for(int i = r; i < indexBulletins; i++){
lesBulletins[i] = lesBulletins[i+1];
}
indexBulletins --;
}
public void modifierBulletin(final Bulletin changed) {
int rang = chercherRang(changed);
if (rang >=0) {
Bulletin aChanger = lesBulletins[rang];
if (aChanger.getValue() != changed.getValue()) {
aChanger.setValue(changed.getValue());
}
if (aChanger.getValue()) {
nbBulletinsContre-- ;
nbBulletinsPour++;
} else {
nbBulletinsContre++ ;
nbBulletinsPour--;
}
}
}
}