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

This is the code that I have so far, however I know it is in correctly please he

ID: 3695678 • Letter: T

Question

This is the code that I have so far, however I know it is in correctly please help :)

//triangle class

public class Triangle1 extends Shape {

     

protected Point vertexA, vertexB, vertexC;

  

   // Length of the 3 sides

   protected double sideAB, sideBC, sideAC;

      

       public Triangle1() {

          sideAB = sideBC = sideAC = 0;

       }

      

   // Constructor : Takes 3 vertices, calculates sides

   public Triangle1 (Point newA, Point newB, Point newC) {

      vertexA = newA;

      vertexB = newB;

      vertexC = newC;

      sideAB = vertexA.distance(vertexB);

      sideBC = vertexB.distance(vertexC);

      sideAC = vertexA.distance(vertexC);

      }

      @Override

   public double computePerimeter() {

      return (sideAB + sideBC + sideAC);

      }

   @Override

   public double computeArea() {

       double s = (sideAB + sideBC + sideAC) /2;

      return (Math.sqrt(s * s-sideAB) * (s-sideBC) * (s-sideAC));

   }

   }

import java.util.*;

public class TestShapes {

   public static void main(String[] args) {

   ArrayList<Shape> shapesList = new ArrayList<Shape>();

     

   Random rand = new Random();

   int randomNumber1 = rand.nextInt(100);

   int randomNumber2 = rand.nextInt(100);

   int randomNumber3 = rand.nextInt(100); //not sure how to apply this within the points

     

   Scanner scnr = new Scanner(System.in);

   System.out.println("Give me the x and y value for the circle");

       int n = scnr.nextInt();  

       Point(n, n); //I know this is incorrect

     

     

     

   Point p = new Point(0,0);

   System.out.println(p.distance(new Point(3,4)));

     

   //Circle

   Circle circle = new Circle(new Point(0,0), 1.0);

   circle.changeRadius(10);

   circle.moveCenter(new Point(4,4));

   shapesList.add(circle);

  

     

   Shape rectangle = new Rectangle(new Point(0.0, 0.0), new Point(1.0, 1.0));

   shapesList.add(rectangle);

     

//triangle

   Shape triangle = new Triangle(new Point (0.0))

      // if(boolean)

  

  

       for (Shape shape : shapesList) {

       System.out.println("Shape is: " + shape.getClass() + " and area is: " + shape.computeArea());

          }

//Not sure how to print them in the correct order

  

System.out.println("Area of circle 1 is: " + circle.computeArea());

System.out.println("Perimeter of circle 1 is: " + circle.computePerimeter());

System.out.println("Area of rectangle is: " + rectangle.computeArea());

System.out.println("Perimeter of rectangle is: " + rectangle.computeArea());

return;

  

  

   }

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

1. private Point vertex1;

2. private Point vertex2;

3. private Point vertex3;

And the following public methods:

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

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

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.

Figure 11.2.1: Shape is an abstract class. Circle and Rectangle are concrete classes that extend the Shape class Point. java holds the x, y coordinates for a point public class Point private double x private double y public Point (double x, double y) Shape.java specifies how a programmer interacts with shapes public abstract class Shapef this.x this.yY abstract double computeArea( public double getxt return xi public double getYt return Rectangle.java defines a Rectangle class public class Rectangle extends Shape i Circle.java defines a Circle class public class circle extends Shape private Point lowerLeft, upperRight Rectangle(Point lowerLeft, Point upperRight) private double radius; private Point center this.loverLeft- lowerleft this.upperRight upperRight; public Circle(Point center, double radius) this.radius radius this.center center; Override public double computeArea) double length-0.0 double height-0.0 Override public double computeArea)f ength upperRight.getxlowerLeft.getx): height - upperkight. gety O- lowerLeft. getY/ ; return (Math. PIMath.pow (radius, 2)): return (length height) TestShapes.java tests the Shape class public class TestShapes ( public static void rain(String args) Circle circlel -new Circle(new Point(0.0, 0.0), 1.0 Circle circle2 -new Circle(new Point(0.0, 0.0), 2.0 Shape rectangle- Rectangle ( new Point( 0 . 0 , 0-0) , new Point( 1 ‘ 0, 1 ‘ 0 )) ; new System.out printin("Area of circle l is: +circlel.computeArea()); System.out, print1n "Area of circle 2 is! + circle2.computeArea()); System.out, print1n "Area of rectangle is: " + rectangle.computeArea )); return; Area of circle 1 is:3.141592653589793 Are of circle 2 is: 12.566370614359172 Are of rectangle is: 1.0

Explanation / Answer

The required code part :

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