In: Computer Science
Java Please
Source Only
Program 3: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source code) a program to compute the distance between 2 points. The program prompts the user to enter 2 points (X1, Y1) and (X2, Y2). The distance between 2 points formula is: Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2] Document your code, properly label the input prompts, and organize the outputs as shown in the following sample runs.
Thanks for the question. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks : ) =========================================================================== import java.util.Scanner; public class ProblemThree { public static void main(String[] args) { // scanner object to accept user input Scanner scanner = new Scanner(System.in); // create four variables double x1, y1, x2, y2; // get x1 and y1 from user System.out.print("Enter X1: "); x1 = scanner.nextDouble(); System.out.print("Enter Y1: "); y1 = scanner.nextDouble(); // get x2 and y2 from user System.out.print("Enter X2: "); x2 = scanner.nextDouble(); System.out.print("Enter Y2: "); y2 = scanner.nextDouble(); //calculate distance using Math.sqrt() method double distance = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); //display distance System.out.println("Distance: "+distance); } }
===========================================================================