From 8c4079384ac0deca558df9a9572d64b2bc2f4f65 Mon Sep 17 00:00:00 2001 From: Gaoyuduo Date: Thu, 7 May 2026 15:33:26 +0800 Subject: [PATCH] =?UTF-8?q?W4-=E9=AB=98=E9=92=B0=E9=93=8E-202506050304?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4.1.txt | Bin 0 -> 1024 bytes public class Circle extends Shape {.txt | 12 ++++++++++++ public class Rectangle extends Shap.txt | 14 ++++++++++++++ public class ShapeUtil {.txt | 5 +++++ public class Test {.txt | 11 +++++++++++ 5 files changed, 42 insertions(+) create mode 100644 4.1.txt create mode 100644 public class Circle extends Shape {.txt create mode 100644 public class Rectangle extends Shap.txt create mode 100644 public class ShapeUtil {.txt create mode 100644 public class Test {.txt diff --git a/4.1.txt b/4.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..06d7405020018ddf3cacee90fd4af10487da3d20 GIT binary patch literal 1024 ScmZQz7zLvtFd70QH3R?z00031 literal 0 HcmV?d00001 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