Browse Source

feat:Shape

main
Sunchenxi 2 weeks ago
parent
commit
f89b9e6660
  1. 0
      w5/AI学习报告.txt
  2. 3
      w5/Shape.java
  3. 56
      w5/ShapeCalculator.java
  4. BIN
      w5/~$ DOCX 文档.docx
  5. BIN
      w5/屏幕截图 2026-03-29 224240.png
  6. BIN
      w5/类图.jpg
  7. BIN
      w5/组合与继承.docx

0
w5/AI学习报告.txt

3
w5/Shape.java

@ -0,0 +1,3 @@
public abstract class Shape {
public abstract void draw();
}

56
w5/ShapeCalculator.java

@ -1,56 +0,0 @@
package w5;
public class ShapeCalculator {
abstract class Shape {
public abstract double getArea();
}
class Circle extends Shape {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
@Override
public double getArea() {
return Math.PI * radius * radius;
}
}
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;
}
}
class Triangle extends Shape {
private double base;
private double height;
public Triangle(double base, double height) {
this.base = base;
this.height = height;
}
@Override
public double getArea() {
return 0.5 * base * height;
}
}
class ShapeUtil {
public static void printArea(Shape shape) {
System.out.println("图形面积为:" + shape.getArea());
}
}
public static void main(String[] args) {
ShapeCalculator calculator = new ShapeCalculator();
Shape circle = calculator.new Circle(5);
Shape rectangle = calculator.new Rectangle(4,6);
Shape triangle = calculator.new Triangle(3,8);
System.out.println("====== 图形面积计算器 ======");
ShapeUtil.printArea(circle);
ShapeUtil.printArea(rectangle);
ShapeUtil.printArea(triangle);
}
}

BIN
w5/~$ DOCX 文档.docx

Binary file not shown.

BIN
w5/屏幕截图 2026-03-29 224240.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

BIN
w5/类图.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

BIN
w5/组合与继承.docx

Binary file not shown.
Loading…
Cancel
Save