Question: JAVA 1. Write an abstract class Shape. a. Include a protected variable double area. b. Include a no argument constructor that sets the area to

JAVA

1. Write an abstract class Shape. a. Include a protected variable double area. b. Include a no argument constructor that sets the area to 0. c. Include an abstract method header calculateArea() with the following features in the signature: i. It is an abstract method ii. It is protected in scope iii. It returns nothing iv. It takes no arguments v. It has no method body 2. Write a class Circle that inherits shape. a. Include one private variable radius; b. Include a constructor that takes one argument, the radius. The constructor should: i. Call the superconstructor ii. Set the radius to the radius passed in to the constructor iii. Call the protected method calculateArea c. Include a protected method calculateArea() with the same signature as the abstract method in Shape. This method will override the parent method. i. calculateArea() should set the area variable to the area of the circle. (Notice that the area variable is located in the Shape class. Thats fine. You can use it because it is in a parent class.) d. Write a getArea() method that returns the area. 3. Write a class Rectangle that inherits shape a. Include private variables for the length and width. b. Include a constructor that accepts the length and width as parameters. The constructor should: i. Call the superconstructor ii. Set the length and width variables in this class to the length and width. iii. Call calculateArea c. Include a protected method calculateArea() with the same signature as the Shape method calculateArea (except that it isnt abstract of course). i. Calculate the area and set the area variable to the area. d. Write a getArea method that simply returns the area. 4. Write a class Square that inherits Rectangle. a. Add a private variable side. b. Add a constructor which takes the side as an argument: i. Calls the Rectangle constructor ii. Sets the side variable in the class to the side that was passed into the constructor iii. Calls calculateArea()

c. Write a calculateArea() method that overrides calculateArea in the Rectangle and Shape classes and which: i. Calls calculate area in the parent or Rectangle class. d. Write a method getArea() that returns the area. 5. Write a class ShapeApp that includes a main method. a. Instantiate a circle object passing in the radius; b. Call the circles getArea method to print the area of the circle.

C. Write a calculateArea() method that overrides calculateArea in the Rectangle and Shape classes and which: i. Calls calculate area in the parent or Rectangle class. d. Write a method getArea() that returns the area. 6. Write a class ShapeApp that includes a main method. a. Instantiate a circle object passing in the radius; b. Call the circles getArea method to print the area of the circle.

c. Instantiate a square object passing in the side

d. Call the sides getArea method to print the area of the square. e. Instantiate a Rectangle object passing in the length and width. f. Call the Rectangles getArea method to print the area of the Rectangle.

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!