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

Hash table of image annotations. Complete the metod equals to return true if the

ID: 675510 • Letter: H

Question

Hash table of image annotations.

Complete the metod equals to return true if the two Point2D objects have the samde coordinates. It should return false if they are not saome

Complete the method hashCode to return a good hase code(using the method shown in class <<--- but i can't remember what was it..) that uses both x and y values for the hash code.

could you please let me know how can i make method hashcode?

here is my Point2D objects.

public final class Point2D {
final int x;
final int y;
final String s;
/** Create a new 2D point with given x and y values
*
* @param xValue is the value for the x-coordinate
* @param yValue is the value for the y-coordinate
*/
public Point2D(int xValue, int yValue,String name) {
x = xValue;
y = yValue;
}
/** Return a string describing the 2D point */
public String toString() {
return "(" + x + ", " + y + ")";
}
  
  
/** Override the default hashcode method */
public int hashCode(){
// TODO: compute hash code that uses both x and y values using method shown in class
// (slides on learninghub)
return x;
}
  
/** Override the default equals method.
* Two Point2D objects equal if their values are equal.
*/
public boolean equals(Object obj) {
if (obj instanceof Point2D == false){
return false;
}
Point2D p = (Point2D) obj;
  
// TODO: return true if this point and the given object describe the same 2D point
// (i.e. x and y values are the same between the two point objects)
  
return true;
}
  
}

And also i have ome more thing. That is Point2DHashTable.java.

the question is ' You will also need to complete the java file Point2DHashTable.java that creates a hash table of oannotations (Strings) whose keys are Point2D objects,'

(a) complete the method displayAnnotations that takes a Point2D object as input and displays its corresponding annotation(if any). If it has no annotation, the function should display a message stating this.

(b) complete the method main to insert the following (key,value) pairs into the hash table

(45,237), "Cat"

(75,47), "Tree"

(467,33), "Boat"

(200, 10), "Grass"

and here is my Point2DHashTable.java

public class Point2DHashTable {
/** Output the annotation for a given 2D point
*
* @param key is the 2D point
* @param annotationMap is a map of annotation string for a set of points
*/
public static void displayAnnotation(Point2D key, HashMap<Point2D, String> annotationMap){
// TODO: display annotation for given 2D point
// if point is not in hash table, display message stating that it has no annotation
}
  
/** Test the equals and hashCode implementations in Point2D
* @param args is an array of command line arguments
*/
public static void main(String[] args) {
// TODO: Create hash map of Point2D objects with their annotations as keys
  
// TODO: Insert points and corresponding strings into table
  
displayAnnotation(new Point2D(467, 237), annotationMap); // should succeed
  
  
}
  
}

.

Explanation / Answer

public int hashCode(){
// TODO: compute hash code that uses both x and y values using method shown in class
// (slides on learninghub)   
return x ^ y;//XOR will be unique for given x and y
}
  

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