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

Hi, I have having some trouble solving this problem. Can someone please help me?

ID: 3730151 • Letter: H

Question

Hi, I have having some trouble solving this problem. Can someone please help me?

public class Point {

private double x;

private double y;

public Point (){

this (0,0);

}

public Point (double a, double b){

/*missing code*/

}

//...other methods not shown

}

which of the following correctly implements the equals method?

A. public boolean equals (Point p){System.out.println(x == p.x && y==p.y);}

B.public void equals (Point P){System.out.println(x == p.x && y == p.y);}

C.public boolean equals (Point p) { return (x == Point.x && y == Point.y);}

D.public boolean equals (Point p){return (x==p.x && y = p.y);}

E.public void equals (Point p){return (x == p.x && y == p.y);}

Explanation / Answer

ANSWER: Here in the given options there is no option is valid all are giving the error and reasons I am giving you below. you can see.

Option(A): Here return type is boolean but this method is returning nothing.so it will give the error.

Option(B): This option will work if we call P.x and P.y because the object is capital P not small p.

Option(C): Here in this option we are calling the variables x and y by class name then it will give the error because x and y variable is not static.

option(D) : public boolean equals (Point p){return (x==p.x && y = p.y);} in this y==p.y is correct substitution for this then it can work as equals method.

Option(E): In this option the return type is void it should be boolean then it can work as equals method.

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