/* Distance.java * Author: Anders * * Translated by: Jesper * * Execise 6: * Calculates the distance between a line * and a point in the plane. */ import cs1.Keyboard; public class Distance{ public static void main(String[] args){ // a and b of the equation // is read from the keyboard. System.out.println("Type in the values of a and b for the equation " + "y = a*x+b"); System.out.print("a = "); double a = Keyboard.readDouble(); System.out.print("b = "); double b = Keyboard.readDouble(); // The coordinates of the point // is read from the keyboard. System.out.println("Type in the coordinates of the point (x, y)"); System.out.print("x = "); double x = Keyboard.readDouble(); System.out.print("y = "); double y = Keyboard.readDouble(); // The distance between the line // and the point is printed double dist = Math.abs(a*x-y+b)/Math.sqrt(1+Math.pow(a,2)); System.out.println("The distance between the line and the point is: " + dist); }// End of the main method } // End of the class