Note that there are some explanatory texts on larger screens.

plurals
  1. POequals() method to check X and Y coordinates
    primarykey
    data
    text
    <p>Ok guys, first off sorry if this code is messy and if my equals() is completely wrong, but this is my first time using it.</p> <p>I'm trying to create an equals method to check if two lines are equal, two lines are defined as equal if two end points are the same.</p> <p>My first question is, am i even close with the method in the Point class, and also how would I call the equals() method in the Point class from the Line class?</p> <p>Thanks for any and all help.</p> <pre><code>public class Point { private int x; private int y; public Point( int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } public String toString() { return "x=" + x + ", y=" + y; } public boolean equals(Object o) { if (!(o instanceof Point)) { return false; } return (x == ((Point) o).x &amp;&amp; y == ((Point) o).y); } } </code></pre> <p>}</p> <p>for the return this.y, it says "unreachable code". Also Should my Object be "Point" or "Line"?</p> <pre><code>public class Line { private Point beg, end; Color color; public Line(Point beg, Point end, String color) { this.beg = beg; this.end = end; public Point getEnd() { return end; } public Point getBeg() { return beg; } public Color getColor() { return color; } public String toString() { return "Beg=" + beg + ", End=" + end + ", Color" + color.toString(); } Line() { return this.beg.equals(Point.x); return this.end.equals(Point.y); } </code></pre> <p>}</p> <p>I updated the equals() in point class but I'm still having trouble calling it from the Line class, would it be a similar fix?</p> <p>Thanks for all the help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload