Question: (A) (18 points) Write a parent class Shape (as shown in the above UML): a. Two instance variable (color (String) and filled (Boolean); make Red

 (A) (18 points) Write a parent class Shape (as shown in

(A) (18 points) Write a parent class Shape (as shown in the above UML):

a. Two instance variable (color (String) and filled (Boolean); make "Red" as default color and filled is true)

b. Two constructors (one with no argument. The other has (String color, Boolean filled))

c. boolean isFilled () is used to "get" filled status (true/false)

d. setColor (..) and setFilled (..) do the color and isFilled respectively

e. toString () returns the color and filled status

f. Write a TestShape program to test the shape default and modified color and filled

The shape color is red and the isFilled status is false

The shape color is pink and the isFilled status is true

g. Write two child classes (Circle and Rectangle) as shown in the UML

(B) (18 points) The Circle Class has:

a. One instance variable: double radius

b. Three Constructors .... (don't forget your parent ...)

c. Setter for radius, color

d. Get area and Perimeters

e. The toString() method that overrides Shape and return the follow

f. Write a Circle test program to display:

The Orange circle area is 28.274333882308138

The Perimeter is 18.84955592153876

filled is true

(C) (17 points) The Rectangular Class has:

a. Two instance variables (double width, double length)

b. Four constructors: use the no-arg one to initialize the width and length to 1.0

c. Getters for width and length, area, perimeters, and inFilled**status

d. The toString() method overrides its parent to return the following

e. Write a Rectangle test program to display:

Rectangle (1.0, 1.0) Area is 1.0, Perimeter is 4.0

color is red

filled is false

Rectangle (4.0, 5.0) Area is 20.0, Perimeter is 18.0

color is Green

filled is true

(D) (15 points) The Square class inherited from the Rectangle class. Note: this class has NO instance variable, but inherits width and length from it parent Rectangle:

a. Three constructors

b. Can it gets the are and perimeter from its parent or does it need to override getArea() and getPerimeter()?

c. The toString() method overrides Rectangle to return the following:

d. Write a Square test program to display:

Square (1.0) Area = 1.0 Perimeter is 4.0 color is red isFilled is false

Square (6.0) Area = 36.0 Perimeter is 24.0 color is purple isFilled is true

(4) (68 points) This question further exercises your knowledge on inheritance (constructors, chaining, super, and toStrina) opertions). The following UML diagram shows Shape as the parent of Circle, and Rectangle which is the parent of Square. For each of the classes write a test program to test the methods defined in them. C Circle G TestCircle Assignment3.com.shape Assignment3.com.shape o radius: double Circle) Circle(double) TestCircle) Circle(double String boolean) e getRadius0 double e getArea0:double e getPerimeter) double o setRadius(double):void etoString0 String > G TestShape Assignments.com.shape > G Shape Assignment3.com.shape color String a filled: boolean TestShape0 Shape) Shape(String.boolean) o getcolor0 String o setColor(String):void o isfilled0 boolean o setFilled(boolean):void o toString):String > G TestSquare Assignment3.com.shape > G Rectangle Assignment3.com.shape > TestSquare0 width double uare Assignment3.com.shape length: double Rectangle) Rectangle(String boolean) Rectangle(double, double) Rectangle(double, String boolean) FRectangle(double,double,String.boolean) e getWidth double o setWidth(double) void o getLength() double o setLength(double) void o getArea) double getPerimeter) double o isFilled():boolean toString0 String > G TestRectangle Assignment3.com.shape Square0 Square(double) Square(double, String boolean) o getSide0 double o getArea(double) double o setSide(double) void o toString0 String TestRectangle0

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!