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 75 76 77 78 79 80 81
|
public class Principal {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Couleur rouge = Couleur.ROUGE;
Couleur bleu = Couleur.BLEU;
Coloriage c1 = new Coloriage(bleu);
Coloriage c2 = new Coloriage(rouge);
Coloriage c3 = new Coloriage(Couleur.ORANGE);
Coloriage c4 = new Coloriage(Couleur.VERT);
c1 = new Coloriage(c2);
c1 = new Coloriage("bleu");
if (c1.equals(c1))
Afficher.obj("\n c1 == c1 ");
if (c1.equals(c2))
Afficher.obj("\n c1 == c2 ");
c1.setCouleur("BLEU");
c1.setCouleur(Couleur.BLEU);
Coloriage c10 = c1.melanger(c2);
Afficher.obj((c10));
Afficher.obj(c10.toString());
Afficher.obj(c10);
Coloriage tabCoul[] = new Coloriage[4];
tabCoul[0] = c1;
tabCoul[1] = c2;
tabCoul[2] = c3;
tabCoul[3] = c4;
if (c1.compareTo(c2) == 0 )
Afficher.obj("==");
Afficher.obj("\n tabCoul = ");
for (int i = 0; i < tabCoul.length; i++) {
Afficher.obj("\n " + tabCoul[i]);
}
Coloriage tabCoulTrie[] = trier(tabCoul);
Afficher.obj("\n tabCoulTrie = ");
for (int i = 0; i < tabCoulTrie.length; i++) {
Afficher.obj("\n " + tabCoulTrie[i]);
}
tabCoul[0].setCouleur(Couleur.VERT);
tabCoul[1].setCouleur(Couleur.ROUGE);
tabCoul[2].setCouleur(Couleur.BLEU);
tabCoul[3].setCouleur(Couleur.ORANGE);
Coloriage tabCoulTrie2[] = (Coloriage[]) Utilitaires.triGen(tabCoul);
triGen erreur ---> la methode triGen(Comprable[]) dans le type utilitaire nest pas appicable pour coloriage[]
Afficher.obj("\n tabCoulTrie 2 = ");
for (int i=0;i<tabCoulTrie2.length;i++){
Afficher.obj("\n : "+tabCoulTrie2[i]);
}
}
private static Coloriage[] trier(Coloriage[] tabCoul) {
// TODO Auto-generated method stub
boolean trie = false;
while(!trie){
trie = true;
for(int j=0;j<tabCoul.length-1;j++){
if(tabCoul[j].getCouleur().ordinal() > tabCoul[j+1].getCouleur().ordinal() ){
permuter(tabCoul, j, j+1);
trie = false;
}
}
}
return tabCoul;
}
private static void permuter(Coloriage[] tab, int i, int j) {
// TODO Auto-generated method stub
Coloriage temp = tab[i];
tab[i] = tab[j];
tab[j] = temp;
}
} |