Create an interface ShapeD which declares a getArea method. Point 3D contains coordinates of a point. The abstract class Shape declares abstract display) method and is extended by Circle class. it implements the Shape2D interface. The Shapes class instantiates this class and exercises its methods.
// Interface Shape2D with a getArea method
interface Shape2D {
double getArea();
}
class Point3D {
double x, y, z;
Point3D(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
}
abstract class Shape {
abstract void display();
}
class Circle extends Shape implements Shape2D {
double radius;
Point3D center;
Circle(double radius, Point3D center) {
this.radius = radius;
this.center = center;
}
public double getArea() {
return Math.PI * radius * radius;
}
void display() {
System.out.println("Circle with radius: " + radius);
System.out.println("Center coordinates: (" + center.x + ", " + center.y + ", " + center.z + ")");
System.out.println("Area: " + getArea());
}
}
public class Shapes {
public static void main(String[] args) {
// Instantiate Circle object
Point3D center = new Point3D(0, 0, 0);
Circle circle = new Circle(5, center);
// Exercise methods
circle.display();
}
}