5 changed files with 32 additions and 0 deletions
Binary file not shown.
@ -0,0 +1,14 @@ |
|||||
|
package w4; |
||||
|
|
||||
|
public class Circle extends Shape { |
||||
|
private double radius; |
||||
|
|
||||
|
public Circle(double radius) { |
||||
|
this.radius = radius; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public double getArea() { |
||||
|
return Math.PI * radius * radius; |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,18 @@ |
|||||
|
package w4.代码; |
||||
|
|
||||
|
import w4.Rectangle; |
||||
|
import w4.Shape; |
||||
|
import w4.ShapeUtil; |
||||
|
import w4.Triangle; |
||||
|
|
||||
|
public class Demo { |
||||
|
public static void main(String[] args) { |
||||
|
Shape circle = new Circle(5.0); |
||||
|
Shape rectangle = new Rectangle(4.0, 6.0); |
||||
|
Shape triangle = new Triangle(3.0, 4.0); |
||||
|
|
||||
|
ShapeUtil.printArea(circle); // Area: 78.54
|
||||
|
ShapeUtil.printArea(rectangle); // Area: 24.00
|
||||
|
ShapeUtil.printArea(triangle); // Area: 6.00
|
||||
|
} |
||||
|
} |
||||
Binary file not shown.
Loading…
Reference in new issue