Cartography (the drawing of maps) is becoming increasingly digital. Digital cart
ID: 3774135 • Letter: C
Question
Cartography (the drawing of maps) is becoming increasingly digital. Digital cartography is especially advantageous by letting users select the size and color of "event radii" (circles showing the area effected by some event). This ability, in turn, is enabled by data structures which not only order data, but can enable efficient searching-binary search trees. On this question, you will answering questions about using binary trees to MapLoc instances, where MapLoc is a class used to represent a single location on a map. is: Because MapLoc instances are NOT Comparable, our binary search tree will need to use a Comparato DiatComp will compare two MapLocs using their distance from origin (the location where an event occurred Complete the DiatComp class so that it performs this comparison.Explanation / Answer
Solution:
public class DistComp implements Comparator<MapLoc>
{
private MapLoc origin;
public DistComp(MapLoc el) {origin=el;}
// method to comapre two map distances from their orgin
public int compare(MapLoc orgin1,MapLoc orgin2)
{
if(origin.distance(origin1) == origin.distance(origin2))
return 0;
return (origin.distance(origin1)- origin.distance(origin2))<0.f?-1:1;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.