/*************************************************** * Your Name * Lab #1 * slope.java * Lab Instructor's Name * Section Number **************************************************** * The purpose of this lab is to familiarize yourself * with debugging code. Debugging is a very important * skill that can only be learned through practice. * The following program has several bugs in it. * These bugs vary in type to expose you to a variety * of errors. Syntax, Run-time, and Logic errors all * appear in this program and it is your job to * identify and correct them where needed. Follow * these steps to complete the lab. * * 1.) Compile the program. * 2.) Write any and all error messages here: * * * * 3.) Correct the error. * 4.) Identify which type of error it was: * * * 5.) Save and compile the corrected program. * 6.) Run the program (or debugg as needed) * 7.) Enter 0 0 for the first point and 1 3 for * the second point. * 8.) Write the output given by the program: * * The slope of the line is . * * 9.) Determine whether the results are reasonable. * * * 10) If the results aren't reasonable, check the * slope formula and make any adjustments needed. * 11) Save and compile again. * 12) Run and write the new output here: * * The slope of the line is . * * 13) Repeat steps 9 - 12 until output is correct. * 14) What kind of error did you just fix? * * * * 15) Run the program again, and enter 0 0 and 0 0 * for the points. * 16) Notice the NaN (Not a Number) answer given * by the computer. What kind of error is this: * * * *********************************************************/ // Finds the slope of a line between two points (x1, y1), // and (x2, y2). import java.io.*; public class Slope extends Object { public static void main(String[] args) { try { BufferedReader myReader = new BufferedReader(new InputStreamReader(System.in)); // Prompt the user for x and y coordinates for the // first point and read them in. System.out.println( "Enter x coordinate of the first point : "); string input = myReader.readLine(); double x1 = Double.parseDouble( input ) System.out.println( "Enter y coordinate of the first point : "); string input = myReader.readLine(); double y1 = Double.parseDouble( input ) // Prompt the user for x and y coordinate for the // second point and read them in. System.out.println( "Enter x coordinate of the second point : "); string input = myReader.readLine(); double x2 = Double.parseDouble( input ) System.out.println( "Enter y coordinate of the second point : "); string input = myReader.readLine(); double y2 = Double.parseDouble( input ) // Calculate and display the slope of the line. double lineSlope = (x2 - x1) / (y2 - y1); System.out.println( "The slope of the line is " + lineSlope); } catch(Exception e) { System.out.println("bad input"); System.exit(1); } // End main } }