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
| import java.util.Enumeration;
import java.util.Random;
import java.util.Vector;
class stock {
private Vector liste;
private piece s;
public stock(Vector liste){
this.liste=liste;
}
public void RempStock(){
int k,i;
liste = new Vector();
for (i=0;i<=6;i++){
for(k=0;k<=6;k++){
s=new piece(0,0);
s.setD(i);
s.setG(k);
liste.add(s);
}
}
for (k=0;k<liste.size();k++){
for(i=0;i<liste.size();i++){
if (liste.elementAt(k).equals(liste.elementAt(i)))
liste.removeElementAt(i);
}
}
}
public Object substock(){
Random r = new Random();
int j = r.nextInt() %28; //entier entre -9 et 9
return liste.elementAt(Math.abs(j));
}
public void view(){
for (Enumeration e = liste.elements() ; e.hasMoreElements() ; ) {
System.out.println(e.nextElement());
}
}
public Vector tout(){
return liste;
}
}
class piece{
private int g;
private int d;
public piece(int g,int d){
this.g=g;
this.d=d;
}
public void setG (int g) { this.g = g ; }
public void setD (int d) { this.d = d ; }
public int getG () { return g ; }
public int getD () { return d ; }
public boolean equals(Object o) {
if(this==o) return true;
if(o instanceof piece) {
piece dp = (piece) o;
return ((g==dp.d ) && (d==dp.g));
}
return false;
}
}
public class essai{
public static void main(String[] args){
Vector v = new Vector();
stock s = new stock(v);
s.RempStock();
System.out.println(s.tout().elementAt(5));
}
} |
Partager