ManipulateurRectangle.java
1.77 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
61
62
63
64
65
import java.util.*;
public class ManipulateurRectangle{
Rectangle[] tabRe;
public void creerTableauRectangle(){
Scanner sc = new Scanner(System.in);
int nbRect;
System.out.println("Nb Rectangle ?");
nbRect = sc.nextInt();
tabRe = new Rectangle[nbRect];
for(int i = 0; i< tabRe.length;i++){
tabRe[i] = creerRectangle();
}
}
public Rectangle creerRectangle(){
Scanner sc = new Scanner(System.in);
double[] valsPoint= new double[4];
for(int i = 0; i < valsPoint.length; i++){
System.out.println("Coord"+i+"= ?");
valsPoint[i] = sc.nextDouble();
}
return new Rectangle(valsPoint[0],valsPoint[1],valsPoint[2],valsPoint[3]);
}
public String toString(){
String res="";
for(int i = 0; i< tabRe.length;i++){
res+= tabRe[i].toString()+"\n";
}
return res;
}
public Rectangle max(Rectangle[] t){
Rectangle res = null;
if(t.length>0){
res = t[0];
double surfaceMax = t[0].surface();
for(int i = 1; i < tabRe.length; i++){
double tmp = t[i].surface();
if( tmp > surfaceMax){
res = t[i];
surfaceMax = tmp;
}
}
}
return res;
}
public void decalerRectangles(double decX, double decY){
for(int i = 0; i < tabRe.length; i++){
tabRe[i].origin.setLocation(tabRe[i].origin.getX()+decX,tabRe[i].origin.getY()+decY);
tabRe[i].corner.setLocation(tabRe[i].corner.getX()+decX,tabRe[i].corner.getY()+decY);
}
}
}