diff --git a/W4周梓浩202506050319/Shape.java b/W4周梓浩202506050319/Shape.java new file mode 100644 index 0000000..cf18e13 --- /dev/null +++ b/W4周梓浩202506050319/Shape.java @@ -0,0 +1,47 @@ +package Shape; + +abstract public class Shape { + abstract double getArea(); +} +class Circle extends Shape{ + private double r; + public Circle(double r){ + this.r=r; + } + @Override + double getArea(){ + return Math.PI*r*r; + } +} + +class Rectangle extends Shape{ + private double chang; + private double kuan; + public Rectangle(double chang,double kuan){ + this.chang=chang; + this.kuan=kuan; + } + @Override + double getArea(){ + return chang*kuan; + } +} + +class Triangle extends Shape{ + private double di; + private double height; + public Triangle(double di,double height){ + this.di=di; + this.height=height; + } + @Override + double getArea(){ + return 0.5*di*height; + } +} + +class ShapeUtil{ + public static void printArea(Shape shape){ + System.out.println("面积是"+shape.getArea()); + } +} \ No newline at end of file diff --git a/W4周梓浩202506050319/ShapeTest.java b/W4周梓浩202506050319/ShapeTest.java new file mode 100644 index 0000000..e9e1767 --- /dev/null +++ b/W4周梓浩202506050319/ShapeTest.java @@ -0,0 +1,14 @@ +package Shape; + +public class ShapeTest { + public static void main(String[] args){ + System.out.println("--测试三个类--"); + //circle + Circle round=new Circle(5); + Rectangle b=new Rectangle(4,7); + Triangle c=new Triangle(8,4); + ShapeUtil.printArea(round); + ShapeUtil.printArea(b); + ShapeUtil.printArea(c); + } +} diff --git a/W4周梓浩202506050319/~$实验报告.docx b/W4周梓浩202506050319/~$实验报告.docx new file mode 100644 index 0000000..9bda992 Binary files /dev/null and b/W4周梓浩202506050319/~$实验报告.docx differ diff --git a/W4周梓浩202506050319/~WRL0197.tmp b/W4周梓浩202506050319/~WRL0197.tmp new file mode 100644 index 0000000..06d7405 Binary files /dev/null and b/W4周梓浩202506050319/~WRL0197.tmp differ diff --git a/W4周梓浩202506050319/实验报告.docx b/W4周梓浩202506050319/实验报告.docx new file mode 100644 index 0000000..c90cc04 Binary files /dev/null and b/W4周梓浩202506050319/实验报告.docx differ