I can\'t figure out how to do this coding. Help please, and thank you for you ti
ID: 3761696 • Letter: I
Question
I can't figure out how to do this coding. Help please, and thank you for you time!
import java.util.HashMap;
/**
* Create a hash table of 2D points and their annotations.
*
* For each point there is string representing an annotation for
* that point in an image.
*
*
*/
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, 33), annotationMap); // should succeed
displayAnnotation(new Point2D(35, 35), annotationMap); // does not have an entry in table
}
}
Explanation / Answer
import java.io.*;
import java.util.*;
class point2D{
int x;
int y;
public point2D(int x,int y){
this.x = x;
this.y = y;
}
}
class main{
public static void displayAnnotation(Point2D key, HashMap<Point2D, String> annotationMap){
if (annotationMap.containsKey(key) == true)
System.out.println(annotationMap.get(key));
else
System.out.println("NO IT IS NOT IN HASHMAP");
System.out.println();
}
public static void main(String[] args){
HashMap<point2D,String> annotationMap = new HashMap<point2D,String>();
hm.put(new point2D(467,33),"YES IT IS IN HASHMAP");
displayAnnotation(new Point2D(467, 33), annotationMap); // should succeed
displayAnnotation(new Point2D(35, 35), annotationMap); // does not have an entry in table
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.