Built-in: Distance Calculation and Magic Numbers

 
 

Write a program Distance_YI.java with these values x1 = 3.0, x2 = 5.0, y1 = 2.5 and y2 = -1.9 and prints the Euclidean distance from the point (x1, y1) to the origin (x2,y2). Your program should display the numbers from each point with exactly the same format, meaning include parenthesis and comma and the distance as one number in a sentence format. This is what it should look like:

“The distance between points (3.0,5.0) and (2.5,-1.9) is 4.8332”


Resources:

Math.sqrt(4) —> 2.0 Math.pow(base,exponent);

Example: Math.pow(2,5) —> 32

Use the following data type and make sure all your code is inside the main method:

double x1 = 3.0;


NOTE: do not use numbers. Use variables. Using numbers is called “MAGIC NUMBERS”
“MAGIC NUMBERS” are consider bad programming practice.

 

In this image and in the video you will see how “constants” are represented and used.