4 changed files with 29 additions and 0 deletions
@ -0,0 +1,29 @@ |
|||||
|
/** |
||||
|
* 三角形(已知底与高):面积 = 底 * 高 / 2 |
||||
|
*/ |
||||
|
public class Triangle extends Shape { |
||||
|
|
||||
|
private final double base; |
||||
|
private final double height; |
||||
|
|
||||
|
public Triangle(double base, double height) { |
||||
|
if (base <= 0 || height <= 0) { |
||||
|
throw new IllegalArgumentException("底和高必须为正数"); |
||||
|
} |
||||
|
this.base = base; |
||||
|
this.height = height; |
||||
|
} |
||||
|
|
||||
|
public double getBase() { |
||||
|
return base; |
||||
|
} |
||||
|
|
||||
|
public double getHeight() { |
||||
|
return height; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public double getArea() { |
||||
|
return base * height / 2.0; |
||||
|
} |
||||
|
} |
||||
|
After Width: | Height: | Size: 174 KiB |
|
After Width: | Height: | Size: 107 KiB |
Binary file not shown.
Loading…
Reference in new issue