You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
623 B
29 lines
623 B
/**
|
|
* 矩形:面积 = 宽 * 高
|
|
*/
|
|
public class Rectangle extends Shape {
|
|
|
|
private final double width;
|
|
private final double height;
|
|
|
|
public Rectangle(double width, double height) {
|
|
if (width <= 0 || height <= 0) {
|
|
throw new IllegalArgumentException("宽和高必须为正数");
|
|
}
|
|
this.width = width;
|
|
this.height = height;
|
|
}
|
|
|
|
public double getWidth() {
|
|
return width;
|
|
}
|
|
|
|
public double getHeight() {
|
|
return height;
|
|
}
|
|
|
|
@Override
|
|
public double getArea() {
|
|
return width * height;
|
|
}
|
|
}
|
|
|