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

Add the following method to the Point class: public int manhattanDistance(Point

ID: 3765589 • Letter: A

Question

Add the following method to the Point class: public int manhattanDistance(Point other) Returns the "Manhattan distance" between the current Point object and the given other Point object. The Manhattan distance refers to how far apart two places are if the person can only travel straight horizontally or vertically, as though driving on the streets of Manhattan. In our case, the Manhattan distance is the sum of the absolute values of the differences in their coordinates; in other words, the difference in x plus the difference in y between the points. public class Point { private int x; private int y; // your code goes here }

Explanation / Answer

public class Point { private int x; private int y; public int manhattanDistance(Point other) { return (this.x - other.x) + (this.y - other.y); } public static void main(String[] args) { Point p1 = new Point(); Point p2 = new Point(); int distance = p1.manhattanDistance(p2); } }

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