-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhenotype.java
More file actions
executable file
·60 lines (48 loc) · 1.48 KB
/
Phenotype.java
File metadata and controls
executable file
·60 lines (48 loc) · 1.48 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 TP_Pois_Mendel;
import java.util.ArrayList;
// Cette classe se compose d'un ensemble d'objets de classe Caractere, stockés dans une ArrayList
public class Phenotype {
private ArrayList<Caractere> listeCaracteres = new ArrayList<Caractere>();
public Phenotype(){}
//Getter
public ArrayList<Caractere> getListeCaracteres() {
return listeCaracteres;
}
Caractere get(int i) {
return listeCaracteres.get(i);
}
Caractere get(String nom) {
Caractere toReturn = null;
for(int i = 0; i < listeCaracteres.size(); i++) {
if (listeCaracteres.get(i).getNom() == nom) {
toReturn = listeCaracteres.get(i);
}
}
return toReturn;
}
void addCaractere(Caractere caractere) {
listeCaracteres.add(caractere);
}
void afficher() {
System.out.println("Phénotype : ");
for(int i = 0; i < listeCaracteres.size(); i++) {
listeCaracteres.get(i).afficher();
}
}
public static void main (String[] args) {
// Test global
Gene gene1 = new Gene("Couleur", 'J');
Gene gene2 = new Gene("Couleur", 'v');
Caractere couleur = new Caractere("Couleur", gene1, gene2, "jaune", "vert");
Gene gene3 = new Gene("Aspect", 'L');
Gene gene4 = new Gene("Aspect", 'r');
Caractere aspect = new Caractere("Aspect", gene3, gene4, "lisse", "rugueux");
Phenotype pheno = new Phenotype();
pheno.addCaractere(couleur);
pheno.addCaractere(aspect);
pheno.afficher();
// Test des méthodes get()
pheno.get(0).afficher();
pheno.get("Aspect").afficher();
}
}