diff --git a/w4+/Circle.class b/w4+/Circle.class new file mode 100644 index 0000000..6931460 Binary files /dev/null and b/w4+/Circle.class differ diff --git a/w4+/Circle.java b/w4+/Circle.java new file mode 100644 index 0000000..0a0e22d --- /dev/null +++ b/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; + } +} \ No newline at end of file diff --git a/w4+/Main.class b/w4+/Main.class new file mode 100644 index 0000000..398bcda Binary files /dev/null and b/w4+/Main.class differ diff --git a/w4+/Main.java b/w4+/Main.java new file mode 100644 index 0000000..45d4722 --- /dev/null +++ b/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); + } +} \ No newline at end of file diff --git a/w4+/Rectangle.class b/w4+/Rectangle.class new file mode 100644 index 0000000..48e626a Binary files /dev/null and b/w4+/Rectangle.class differ diff --git a/w4+/Rectangle.java b/w4+/Rectangle.java new file mode 100644 index 0000000..7e39dbe --- /dev/null +++ b/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; + } +} \ No newline at end of file diff --git a/w4+/Shape.class b/w4+/Shape.class new file mode 100644 index 0000000..64e3efd Binary files /dev/null and b/w4+/Shape.class differ diff --git a/w4+/Shape.java b/w4+/Shape.java new file mode 100644 index 0000000..9b09498 --- /dev/null +++ b/w4+/Shape.java @@ -0,0 +1,3 @@ +abstract class Shape { + public abstract double getArea(); +} \ No newline at end of file diff --git a/w4+/ShapeUtil.class b/w4+/ShapeUtil.class new file mode 100644 index 0000000..dd3415a Binary files /dev/null and b/w4+/ShapeUtil.class differ diff --git a/w4+/ShapeUtil.java b/w4+/ShapeUtil.java new file mode 100644 index 0000000..c7cfac3 --- /dev/null +++ b/w4+/ShapeUtil.java @@ -0,0 +1,5 @@ +class ShapeUtil { + public static void printArea(Shape shape) { + System.out.printf("%.2f%n", shape.getArea()); + } +} \ No newline at end of file diff --git a/w4+/Triangle.class b/w4+/Triangle.class new file mode 100644 index 0000000..a953a7d Binary files /dev/null and b/w4+/Triangle.class differ diff --git a/w4+/Triangle.java b/w4+/Triangle.java new file mode 100644 index 0000000..7277e62 --- /dev/null +++ b/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; + } +} \ No newline at end of file