Question: JAVA question create an abstract class, Shape, that stores information about simple shapes. Shape includes two abstract public methods, double perimeter(), and double area(), which

JAVA question

create an abstract class, Shape, that stores information about simple shapes.

Shape includes two abstract public methods, double perimeter(), and double area(), which return the length of the perimeter and the area of the shape respectively. Create two additional classes, Square and Circle, each of which extends Shape, and each of which takes a single double length argument in its constructor, which describes the radius (in the case of a circle) or side-length (in the case of a polygon). Add a main method to Shape which includes the following code:

Shape s1 = new Square(10); // a square with sides of 10.0 units Shape s2 = new Circle(1.0); // a circle of radius 1.0 units System.out.println(s1.perimeter()); System.out.println(s1.area()); System.out.println(s2.perimeter()); System.out.println(s2.area()); You should produce the following output:

40.0 100.0 6.283185307179586 3.141592653589793 Add the ability of store the xy-position of the center of each shape:

Add x and y fields to Shape. For each shape add a second constructor that takes three doubles as arguments, length, x, and y. Add an abstract public method boolean overlaps(Shape other) to Shape that takes a single Shape as an argument and returns true if the other shape overlaps the shape it is called on. Assume the squares are upright (parallel to the axis).

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!