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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| public class Ens2 implements EnsInterface
{
private static final int MAX = Elt.MAXELT.val();
private Elt[] t;
private int cardinal;
public Ens2()
{
this.cardinal = 0;
this.t = new Elt[MAX];
}
public boolean estVide()
{
return (this.cardinal == 0);
}
public boolean contient(Elt e)
{
for(int i = 0; i < this.cardinal; i++)
{
if(this.t[i].equals(e))
{
return true;
}
}
return false;
}
public void ajouter(Elt e)
{
if(this.contient(e))
{
this.t[this.cardinal] = new Elt(e);
this.cardinal++;
}
}
public void enlever(Elt e)
{
for(int i = 0; i < this.cardinal; i++)
{
if(this.t[i].equals(e))
{
this.t[this.cardinal - 1] = this.t[i];
}
}
this.cardinal--;
}
public void complémenter()
{
boolean[] temp = new boolean[MAX];
for(int i = 0; i <= MAX; i++)
{
temp[i] = false;
}
for(int j = 0; j <= MAX; j++)
{
temp[t[j].val()] = true;
}
this.cardinal = 0;
for(int k = 0; k <= MAX; k++)
{
if(temp[k] == true)
{
this.t[cardinal + 1] = new Elt(k);
this.cardinal++;
}
}
}
public int cardinal()
{
return this.cardinal;
}
public String toString()
{
String resultat = "{";
if (!this.estVide())
{
resultat += this.t[0].val();
}
for(int i = 1; i < this.cardinal; i++)
{
resultat += "," + this.t[i].val();
}
return resultat += "}";
}
public Elt unEltAuHazard()
{
if(this.estVide())
{
return null;
}
else
{
double nombre;
Elt resultat;
nombre = Math.random();
resultat = Elt((nombre * (1 - this.cardinal + 1)+ 1)); // Erreur !!
return resultat;
}
}
} |