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
| public class Generateur {
private PrintWriter file;
private String ordre;
private int min, max;
private int n;
public Generateur(String nom, int min, int max, String ordre){
try {
file = new PrintWriter(new BufferedWriter(new FileWriter(nom)));
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
this.ordre = ordre;
this.min = min;
this.max = max;
getNbDonnees();
System.out.println(min);
System.out.println(max);
System.out.println(ordre);
if(ordre.equals("Croissant")){
getDonneesCroissantes();
}else {
if(ordre.equals("Decroissant")){
getDonneesDecroissantes();
} else {
if(ordre.equals("")){
getDonneesQuelconque();
}
}
}
}
private int getNbDonnees() {
Random r = new Random();
n = r.nextInt(max-min+1)+min;
System.out.println(" "+n);
return n;
}
private void getDonneesCroissantes() {
int k = 2;
for(int i = 0; i<n; i++){
Random r = new Random();
k = k + r.nextInt(max-min+1)+min;
file.printf(" " + k);
}
file.close();
}
private void getDonneesDecroissantes() {
int k = 1;
for(int i = 0; i<n; i++){
Random r = new Random();
k = k - r.nextInt(max-min+1)+min;
file.printf(" " + k);
}
file.close();
}
private void getDonneesQuelconque() {
int k = 0;
for(int i = 0; i<n; i++){
Random r = new Random();
k = r.nextInt(max-min+1)+min;
file.printf(" " + k);
}
file.close();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int a = Integer.parseInt(args[1]);
int b = Integer.parseInt(args[2]);
Generateur g = new Generateur(args[0],a,b,args[3]);
}
} |