Question: 2 - manhattanDistance ( 1 0 points ) : This method, manhattanDistance, takes four double variables, x 1 , x 2 , y 1 ,

2- manhattanDistance (10 points):
This method, manhattanDistance, takes four double variables, x1, x2, y1, and y2, as
inputs. These variables represent the coordinates of two points in a 2-dimensional plane:
(1,1) and (2,2) respectively. The method must calculate the Manhattan distance between
these two points and return the result as a double.
The Manhattan distance is calculated by taking the sum of the absolute values of the differences in the coordinates:
=|12|+|12|
Calculate the result and assign it to the variable distance.
Step-by-step workflow:
1. Find the absolute value of the difference between x1 and x2 and store that in a custom variable. For example, if x1 is 2.5 and x2 is 5.2, your variables value must be 2.7.
2. Find the absolute value of the difference between y1 and y2 and store that in a custom variable. For example, if y1 is 3.7 and y2 is 7.8, your variables value must be 4.1.
3. Using your two custom variables from the above steps, assign distance to be the sum of your two variables.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!