Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+d) What can you say about the strength of the relationship?

Answered: 1 week ago

Question

What is the APR of 24.10% compounded daily?

Answered: 1 week ago

Question

Define an unfair labor practice and provide three or four examples.

Answered: 1 week ago