Question: BASED ON: 1) public abstract class Shape { protected Point position; abstract double computeArea(); public Point getPosition() { return this .position; } public void setPosition(

BASED ON: 1) public abstract class Shape { protected Point position; abstract double computeArea(); public Point getPosition() { return this.position; } public void setPosition(Point position) { this.position = position; } public void movePositionRelative(Point position) { double x = this.position.getX() + position.getX(); double y = this.position.getY() + position.getY(); this.position.setX(x); this.position.setY(y); return; } } 

2)

public class Point { private double x; private double y; public Point(double x, double y) { this.x = x; this.y = y; } public double getX() { return x; } public double getY() { return y; } public void setX(double x) { this.x = x; return; } public void setY(double y) { this.y = y; return; } } 

3)

public class Circle extends Shape { private double radius; public Circle(Point center, double radius) { this.radius = radius; this.position = center; } @Override public double computeArea() { return (Math.PI * Math.pow(radius, 2)); } } 

4)

public class Rectangle extends Shape { private double length, height; Rectangle(Point upperLeft, double length, double height) { this.position = upperLeft; this.length = length; this.height = height; } @Override public double computeArea() { return (length * height); } } 

Extend:

1) The Shape abstract superclass to have an abstract method called double computePerimeter() that computes the perimeter of the shape

2) Point class contains the public method

- double distance(Point p): which computes the distance from a given point p passed in as a parameter;

3) Circle subclass, concrete extension of Shape, has also the following public methods:

- void moveCenter(Point P): changes the center to point P, radius remains unchanged;

- void changeRadius(double r): changes the value of the radius to r

4) Triangle subclass is a concrete extension of Shape, and has the following private attributes:

- private Point vertex1;

- private Point vertex2;

- private Point vertex3;

And the following public methods:

- boolean isRight(): returns true if the triangle is a right triangle, false otherwise

- boolean isEquilateral(): returns true if the triangle is equilateral, false otherwise

Note: Use Herons formula to compute the area and use Pythagorean theorem to check if the triangle is right. Also, if the 3 given vertices are on a line, and therefore we do not have a triangle, computeArea should return the value 0.

5) Rectangle subclass, concrete extension of Shape, has also the following public method:

- boolean isSquare(): returns true if the rectangle is a square, false otherwise

Note: A rectangle is defined by 2 points (upper right corner and lower left corner). If the points have the same x coordinate or the same y coordinate, the rectangle is actually not defined. In this case, computeArea should return the value 0.

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!