OneCompiler

javacode

Write a program to represent geometric shapes and some operations that can be performed on
them. The idea here is that shapes in higher dimensions inherit data from lower dimensional
shapes. For example, a cube is a three-dimensional square. A sphere is a three-dimensional circle.
The circle, sphere all shares the attribute radius. The square and cube share the attribute side
length. There are various ways to use inheritance to relate these shapes but please follow the
inheritance described below:
All shapes inherit getName() and getArea () methods from the superclass Shape.
Specification:
Your program will consist of the following classes: Shape, Circle, Square, Cube and Sphere.
Your classes may only have the class variables specified in the table below. You will implement
the methods specified in the super class Shape and have them return the appropriate values for
each shape in terms of Area and the Name of the Shape.
Class Class Variable Constructor Extends
Shape String name Shape()
Circle double radius Circle( double r, String n ) Shape
Square double side Square( double s, String n ) Shape
Cylinder double height Cylinder(double h, double r, String n ) Circle
Sphere None Sphere( double r, String n ) Circle

No answers yet!

4 years ago by