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.
30 lines
653 B
30 lines
653 B
public class Rectangle extends Shape{
|
|
private double length;
|
|
private double width;
|
|
|
|
public Rectangle(double length, double width) {
|
|
if (length <= 0 || width <= 0) {
|
|
throw new IllegalArgumentException("长和宽必须大于0");
|
|
}
|
|
this.length = length;
|
|
this.width = width;
|
|
}
|
|
|
|
@Override
|
|
public double getArea() {
|
|
return length * width;
|
|
}
|
|
|
|
@Override
|
|
public String getShapeName() {
|
|
return "长方形";
|
|
}
|
|
|
|
public double getLength() {
|
|
return length;
|
|
}
|
|
|
|
public double getWidth() {
|
|
return width;
|
|
}
|
|
}
|
|
|