Rectangle.java
919 Bytes
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
package rectangles;
import java.awt.geom.Point2D;
public class Rectangle {
public Point2D.Double origin;
public Point2D.Double corner;
public Rectangle(double x1, double y1, double x2, double y2) {
origin = new Point2D.Double(x1, y1);
corner = new Point2D.Double(x2, y2);
}
public double largeur() {
double calcX, calcY;
calcX = (Math.abs(origin.getX() - corner.getX()));
calcY = (Math.abs(origin.getY() - corner.getY()));
return Math.min(calcX, calcY);
}
public double longueur() {
double calcX, calcY;
calcX = (Math.abs(origin.getX() - corner.getX()));
calcY = (Math.abs(origin.getY() - corner.getY()));
return Math.max(calcX, calcY);
}
public double surface() {
return (largeur() * longueur());
}
public double perimetre() {
return (2 * largeur() + 2 * longueur());
}
public String toString() {
return "(" + origin.toString() + "," + corner.toString() + ")";
}
}