Browse Source

上传文件至 'W4'

// 抽象图形类
abstract class Shape {
    public abstract double getArea();
}

// 圆形
class Circle extends Shape {
    private double r;

    public Circle(double r) {
        this.r = r;
    }

    @Override
    public double getArea() {
        return Math.PI * r * r;
    }
}

// 矩形
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());
    }
}
pull/2/head
pangyaxuan 3 weeks ago
parent
commit
d01244e8e8
  1. BIN
      W4/exported_image (1).png
  2. BIN
      W4/实验报告.docx
  3. BIN
      W4/屏幕截图 2026-03-29 231513.png
  4. BIN
      W4/文字文稿1.docx

BIN
W4/exported_image (1).png

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

BIN
W4/实验报告.docx

Binary file not shown.

BIN
W4/屏幕截图 2026-03-29 231513.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

BIN
W4/文字文稿1.docx

Binary file not shown.
Loading…
Cancel
Save