diff --git a/4.1.txt b/4.1.txt new file mode 100644 index 0000000..06d7405 Binary files /dev/null and b/4.1.txt differ diff --git a/public class Circle extends Shape {.txt b/public class Circle extends Shape {.txt new file mode 100644 index 0000000..584068d --- /dev/null +++ b/public class Circle extends Shape {.txt @@ -0,0 +1,12 @@ +public class Circle extends Shape { + private double radius; + + public Circle(double radius) { + this.radius = radius; + } + + @Override + public double getArea() { + return Math.PI * radius * radius; + } +} \ No newline at end of file diff --git a/public class Rectangle extends Shap.txt b/public class Rectangle extends Shap.txt new file mode 100644 index 0000000..90cb267 --- /dev/null +++ b/public class Rectangle extends Shap.txt @@ -0,0 +1,14 @@ +public class Rectangle extends Shape { + private double width; + private double height; + + public Rectangle(double width, double height) { + this.width = width; + this.height = height; + } + + @Override + public double getArea() { + return width * height; + } +} \ No newline at end of file diff --git a/public class ShapeUtil {.txt b/public class ShapeUtil {.txt new file mode 100644 index 0000000..cf3fe54 --- /dev/null +++ b/public class ShapeUtil {.txt @@ -0,0 +1,5 @@ +public class ShapeUtil { + public static void printArea(Shape shape) { + System.out.println("图形面积 = " + shape.getArea()); + } +} \ No newline at end of file diff --git a/public class Test {.txt b/public class Test {.txt new file mode 100644 index 0000000..d43e8ff --- /dev/null +++ b/public class Test {.txt @@ -0,0 +1,11 @@ +public class Test { + public static void main(String[] args) { + Shape circle = new Circle(2); + Shape rectangle = new Rectangle(3, 4); + Shape triangle = new Triangle(4, 5); + + ShapeUtil.printArea(circle); + ShapeUtil.printArea(rectangle); + ShapeUtil.printArea(triangle); + } +} \ No newline at end of file