20120129

Java Project #6 : Points Distance


/**
 * PointsDistance computes the distance between two points in the two dimensional plane.
 * 
 * @author (Andrew Samuels) 
 * @version (02-04-2010)
 */

//import Scanner from library
import java.util.Scanner;

public class PointsDistance
{
    public static void main(String[] args)
    {
        //create distance formula variables
        double x1;
        double y1;
        double x2;
        double y2;
        double distanceBetweenPoints;
        
        //Create Scanner
        Scanner keyboard = new Scanner(System.in);
        
        //capture x1 from user
        System.out.print("Please enter x coordinate of first point: ");
        x1 = keyboard.nextDouble();
        
        //capture y1 from user
        System.out.print("Please enter y coordinate of first point: ");
        y1 = keyboard.nextDouble();
        
        //capture x2 from user
        System.out.print("Please enter x coordinate of second point: ");
        x2 = keyboard.nextDouble();
        
        //capture y2 from user
        System.out.print("Please enter y coordinate of second point: ");
        y2 = keyboard.nextDouble();
        
        
        //calculate distance between points using distance forumula
        distanceBetweenPoints = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        
        
        //print distance between the points
        System.out.println("Distance between (" + x1 + ", " + y1 + ") and (" + x2 + ", " + y2 +") is: " + distanceBetweenPoints);
    }
}