Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the definitions of the class Point, the abstract Class Shape, and the conc

ID: 3695170 • Letter: G

Question

Given the definitions of the class Point, the abstract Class Shape, and the concrete extensions Circle and Rectangle in Chapter 11 of the zyBook, extend them so that The Shape abstract superclass has also the abstract method

• double computePerimeter(): it computes the perimeter of the shape

> Point class contains has also the public method

• double distance(Point p): which computes the distance from a given point p;

> Circle subclass, concrete extension of Shape, contains also has 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

> 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 Heron’s 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.

> 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.

Finally, create a class NewTestShapes containing a main program which will test all the functionalities of the created classes. For instance, as a first set of tests, you could:

1. randomly generate 3 objects of type Point, P1, P2 and P3, and compute the distance between each pair of point;

2. compute area and perimeter of the triangle defined by the 3 points and check if the triangle is a right triangle or equilateral

3. given the 3 rectangles defined by P1 and P2, by P2 and P3 and by P1 and P3, check if they are square and if they have the same areas or perimeters

4. compute the areas and the perimeters of the circles a. with center P1 and radius the distance(P1, P2) b. with center P2 and radius the distance(P2,P3)

5. Finally, create an ArrayList of shapes and add to it the six shapes defined at steps 2, 3 and 4. 6. Sort the arrayList first in increasing order with respect to the perimeters of the shapes, and then in increasing order with respect to the areas of the shapes.

Explanation / Answer

I am posted the code related to changes you want. While posting code, please post text instead of images, it saves time for us to rewrite every thing.

Please note I posted code related to changes done by me only, not everything.

I added the following changes.

1) Shape - double computePerimeter():

2)Point -distance(Point p)

3)Circle - moveCenter

4) Circle - changeRadius

5) Rectangle -isSquare()

6) Test class

import java.io.IOException;

public class NewTestShapes {
   public static void main(String[] args) throws IOException {
       Point p = new Point(0,0);
       System.out.println(p.distance(new Point(3,4)));
      
       Circle circle1 = new Circle(new Point(0,0), 1.0);
       circle1.changeRadius(10);
       circle1.moveCenter(new Point(4,4));
       System.out.println(" Perimeter of the circle 1 is : "+circle1.computePerimeter());

       Rectangle rectangle = new Rectangle(new Point(0.0,0.0), new Point (1.0,1.0));
       System.out.println(" Is square: "+rectangle.isSquare());
   }
}

abstract class Shape {
   abstract double computePerimeter();
}


class Point {
   private double x;
   private double y;
   public Point(double x, double y) {
       this.x = x;
       this.y = y;
   }
  
   public double distance(Point p) {
       double dist = 0;
       dist = Math.sqrt((x-p.getX()) * (x-p.getX())+(y-p.getY()) * (y-p.getY()));
       return dist;
   }
  
   public double getX() {
       return x;
   }
   public void setX(double x) {
       this.x = x;
   }
   public double getY() {
       return y;
   }
   public void setY(double y) {
       this.y = y;
   }
  
  
}

class Circle extends Shape {

   private double radius;
   private Point center;
  
   public void moveCenter(Point p) {
       this.center = p;
   }
  
   public void changeRadius(double r) {
       this.radius =r;
   }
}

class Rectangle extends Shape {
   private Point lowerLeft, upperRight;
   public boolean isSquare() {

  
       double length = upperRight.getX() - lowerLeft.getX();
       double height = upperRight.getY() - lowerLeft.getY();
       //if its not rectangle
       if(length != 0 && height == 0) {
           return (length == height);
       }
       return false;
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote