Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help fixing Java translate method for a triangle: import java.awt.geom.Point2D; import java.awt.geom.Point2D.Double; public class Triangle { private Point2D.Double p1; private Point2D.Double p2; private Point2D.Double p3;

Help fixing Java translate method for a triangle:

import java.awt.geom.Point2D;

import java.awt.geom.Point2D.Double;

public class Triangle {

private Point2D.Double p1;

private Point2D.Double p2;

private Point2D.Double p3;

// Constructor

/*

* Constructs a Triangle object with the given parameters

*/

public Triangle(Point2D.Double p1, Point2D.Double p2, Point2D.Double p3) {

this.p1 = p1;

this.p2 = p2;

this.p3 = p3;

}

public Triangle(Triangle t2) {

this.p1= (Double) t2.getP1();

this.p2= (Double) t2.getP2();

this.p3= (Double) t2.getP3();

}

//Getters

public Point2D getP1(){

return this.p1;

}

public Point2D getP2(){

return this.p2;

}

public Point2D getP3(){

return this.p3;

}

* Return a NEW Triangle that represents the translation of the target Triangle

* by deltaX units horizontally and deltaY units vertically

*/

public Triangle translate(double deltaX, double deltaY) {

//FIX thanks!

Triangle triangle = new Triangle(this.p1,this.p2,this.p3);

triangle.translate(deltaX, deltaY);

Triangle triangle2 = new Triangle(triangle);

return triangle2; // Dummy return

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions