Enclosure

Circle

Square

interface Enclosure { public double perimeter(); public double area(); } class Circle { double radius; Circle(double radius) { this.radius = radius; } } class Square { double width; Square(double width) { this.width = width; } }

class EnclosureTest { public static void main(String[] args) { Enclosure[] enclosures = new Enclosure[2]; enclosures[0] = new Circle(5.0); enclosures[1] = new Square(10.0); for (int n = 0; n < enclosures.length; n++) System.out.println("area = " + enclosures[n].area() +", perimeter = " + enclosures[n].perimeter()); } }

PI

Math

Math.PI

area = 78.53981633974483, perimeter = 31.41592653589793 area = 100.0, perimeter = 40.0

Enclosure.txt

Enclosuretest.txt