Question: QUESTION: Write a class called Line that represents a line segment between two Points. Your Line objects should have the following methods: public Line(Point p1,
QUESTION:
Write a class called Line that represents a line segment between two Points. Your Line objects should have the following methods: public Line(Point p1, Point p2) Constructs a new Line that contains the given two Points. public Point getP1() Returns this Lines first endpoint. public Point getP2() Returns this Lines second endpoint. public String toString() Returns a String representation of this Line, such as "[(22, 3), (4, 7)]".
MY ANSWER:
public class Line // This is the class and file name { // Open curly bracket opens the class Line private Point p1; private Point p2; public Line(Point p1, Point p2) { this.p1 = p1; this.p2 = p2; } public Point getP1() { return p1; } public Point getP2() { return p2; } public String toString() { return "[(" + point1.x + "," + point1.y + "), (" + point2.x + "," + point2.y +")]"; } // Closing bracket closes the method } // Closing bracket closes the class
My code has errors can you please help me and help with writing a comment for each line
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
