ZhengJiayin 1 month ago
parent
commit
80793ab7a3
  1. BIN
      w4+/Circle.class
  2. 12
      w4+/Circle.java
  3. BIN
      w4+/Main.class
  4. 11
      w4+/Main.java
  5. BIN
      w4+/Rectangle.class
  6. 14
      w4+/Rectangle.java
  7. BIN
      w4+/Shape.class
  8. 3
      w4+/Shape.java
  9. BIN
      w4+/ShapeUtil.class
  10. 5
      w4+/ShapeUtil.java
  11. BIN
      w4+/Triangle.class
  12. 14
      w4+/Triangle.java

BIN
w4+/Circle.class

Binary file not shown.

12
w4+/Circle.java

@ -0,0 +1,12 @@
class Circle extends Shape {
private double radius;
Circle(double radius) {
this.radius = radius;
}
@Override
public double getArea() {
return Math.PI * radius * radius;
}
}

BIN
w4+/Main.class

Binary file not shown.

11
w4+/Main.java

@ -0,0 +1,11 @@
public class Main {
public static void main(String[] args) {
Shape circle = new Circle(5.0);
Shape rectangle = new Rectangle(4.0, 6.0);
Shape triangle = new Triangle(3.0, 8.0);
ShapeUtil.printArea(circle);
ShapeUtil.printArea(rectangle);
ShapeUtil.printArea(triangle);
}
}

BIN
w4+/Rectangle.class

Binary file not shown.

14
w4+/Rectangle.java

@ -0,0 +1,14 @@
class Rectangle extends Shape {
private double width;
private double height;
Rectangle(double width, double height) {
this.width = width;
this.height = height;
}
@Override
public double getArea() {
return width * height;
}
}

BIN
w4+/Shape.class

Binary file not shown.

3
w4+/Shape.java

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

BIN
w4+/ShapeUtil.class

Binary file not shown.

5
w4+/ShapeUtil.java

@ -0,0 +1,5 @@
class ShapeUtil {
public static void printArea(Shape shape) {
System.out.printf("%.2f%n", shape.getArea());
}
}

BIN
w4+/Triangle.class

Binary file not shown.

14
w4+/Triangle.java

@ -0,0 +1,14 @@
class Triangle extends Shape {
private double base;
private double height;
Triangle(double base, double height) {
this.base = base;
this.height = height;
}
@Override
public double getArea() {
return 0.5 * base * height;
}
}
Loading…
Cancel
Save