Create two subclasses of shape circle and square then you


Need help with this java program

use the code below to solve this problem

The Shape class is abstract and contains o ne method: getArea. Your task is to create two subclasses of Shape: Circle and Square. Then, you should write a driver program with a main method that creates an array capable of holding four Shape objects.

Populate your array with two Circle objects and two Square objects. Finally, call the getArea method on each Shape in your array and display the results You should not make any changes to Shape.java.

Hints: In case you have repressed your memories of geometry class, the area of

a circle is pi times the radius squared, where pi is approximately 3.14159. Java has the value of pi stored more accurately as the constant Math.PI. The area of a square is the length of its side, squared. You will likely need to declare fields in your Circle and Square classes to hold the radius and side length, respectively.

You will also need constructors for each class, to initialize the fields of the class.

Example Assume your array of Shape object contains the following:

A circle with a radius of 1

A circle with a radius of 5.27

A square with a side of length 14

A square with a side of length 10

Then the output of your driver program should be:

3.141592653589793

87.25113860888395

196.0

100.0

here is the code so far:

******lab.pkg1.practice.starting.code******(driver class)

package lab.pkg1.practice.starting.code;

public class Lab1PracticeStartingCode {

public static void main(String[] args) {
// TODO write code here to create an array of four Shape objects,
// call the getArea method of each one, and display the results.
}

}

*****shape.java*******

package lab.pkg1.practice.starting.code;

public abstract class Shape {

public abstract double getArea();
}

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Create two subclasses of shape circle and square then you
Reference No:- TGS02869552

Expected delivery within 24 Hours