Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA create an abstract class, `Shape` , that stores information about simple shapes. * `Shape` includes two abstract public methods, `double perimeter()` , and `double
JAVA
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 `double`s 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started