Question: Given the following Java classes. public abstract class Shape { protected String name; public Shape( String n ) { name = n; } public abstract

Given the following Java classes.

public abstract class Shape {

protected String name;

public Shape( String n ) {

name = n;

}

public abstract double getArea();

public String getName() { return name; }

}

public class Point {

private double x, y;

public Point( double a, double b ) { setPoint( a, b ); }

public void setPoint( double a, double b ) {

x = a;

y = b;

}

public double getX() { return x; }

public double getY() { return y; }

public String toString() {

return "[" + x + ", " + y + "]";

}

}

Shown below is a tentative program for testing Shape and its subclasses.

public class TestShape {

public static void main( String [] args ) {

Shape[] myShapes = new Shape[3];

myShapes[0] = new Circle( 10.5, 20, 25 );

myShapes[1] = new Rectangle( 30.5, 23.5, 15.5, 20.5 );

myShapes[2] = new Circle( 8, 9.5, 10.5 );

for ( int i = 0; i < myShapes.length; i++ ) {

System.out.println(myShapes[i].getName() + "="

+ myShapes[i].toString() + "; Area="

+ myShapes[i].getArea() );

}

}

}

Write a class Circle which inherits from Shape. The additional variables of Circle are shown below.

Variable name

Data type

radius

double

center

Point

The additional methods of Circle are shown below.

Method name

Description

Inputs

Output

Circle()

Constructor. It accepts 3 double numbers and assigns them to the radius, x, and y coordinates of the center, respectively. It also sets the name as circle by calling an appropriate constructor in the superclass.

3 double values

none

getRadius()

Returns the value of the radius variable.

none

a double value

getCenter()

Returns the center Point of the circle.

none

a Point object

setRadius()

Set the radius variable to the value of the input parameter.

a double value

none

setCenter()

Set the center variable to the Point passed as input parameter.

a Point object

none

getArea()

Returns the area of the circle.

none

a double value

toString()

Returns a description of the circle.

none

a String

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!