Question: Design the class named Circle that extends the class GeometricObjects . The Circle class contains: A double data field called radius , with default values

Design the class named Circle that extends the class GeometricObjects. The Circle class contains:

A double data field called radius , with default values of 1.0, to denote the radius of the circle

A no-arg constructor that creates a default circle.

A full-arg constructor that creates a circle with the specified radius, color and filled properties.

A getter and setter method to get the instance variable radius

A method named getPerimeter() that returns the perimeter of the circle. Perimeter of the circle can be calculated as 2*radius*3.14.

A method named getArea() that returns the area of the circle. Area of the circle can be calculated as 3.14*radius*radius.

A method named toString() that returns a String description of circle as follows:

super.toString() + Circle : radius = + radius + area is : + getArea() + perimeter is : + getPerimeter();

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

CODE FOR GEOMETRIC OBJECTS:

public class GeometricObjects{

private String color;

private Boolean filled;

public GeometricObjects(){

this.color = "white";

this.filled = false;

}

/*Construct Geometric Object with specified color and filled value*/

public GeometricObjects(String color, boolean filled){

this.color = color;

this.filled = filled;

}

/* Return Color*/

public String getColor(){

return color;

}

/*Return filled. since filled is boolean we name it isFilled*/

public boolean isFilled(){

return filled;

}

/*Set new color*/

public void setColor(String color) {

this.color = color;

}

/*Set new filled*/

public void setFilled(boolean filled){

this.filled = filled;

}

/* toString method that returns the string representation of object. This method also fetches the values of color and filled--- i.e. works like a getter too*/

public String toString(){

return "Object color is: " + this.getColor() + " object filled is: " + this.isFilled() ;

}

}

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!