Blame view

tp1_rectangle/tp1/rectangles/ManipulateurRectangle.java 1.83 KB
f98eb12b   Vincent Benoist   tp1Fini
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[] tabRect;
      
      public void creerTableauRectangle(){
          Scanner sc = new Scanner(System.in);
          int nbRect=0;
          System.out.println("Nb Rectangle ?");
          nbRect = sc.nextInt();
          if(nbRect>0){
              tabRect = new Rectangle[nbRect];
          
              for(int i = 0; i< tabRect.length;i++){
                  tabRect[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< tabRect.length;i++){
               res+= tabRect[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 < tabRect.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 < tabRect.length; i++){
                  tabRect[i].origin.setLocation(tabRect[i].origin.getX()+decX,tabRect[i].origin.getY()+decY);
                  tabRect[i].corner.setLocation(tabRect[i].corner.getX()+decX,tabRect[i].corner.getY()+decY);
              }
      }
  }