Practice-It! logo

BJP3 Exercise 8.5: slopePoint

Added by: Will Beebe on 2013/04/01
Keywords: classes

Add the following method to the Point class:

public double slope(Point other)

Returns the slope of the line drawn between this Point and the given other Point. Use the formula (y2 - y1) / (x2 - x1) to determine the slope between two points (x1, y1) and (x2, y2). Note that this formula fails for points with identical x-coordinates, so throw an IllegalArgumentException in this case.

public class Point {
    private int x;
    private int y;
    
    // your code goes here
    
}

You must log in before you can solve this problem.

user
Log In


indent Re-indent

If you do not understand how to solve a problem or why your solution code doesn't work, please contact your TA or instructor.

If something seems wrong with the Practice-It system itself (errors, slow performance, incorrect problem descriptions/tests, etc.), please contact us.

Is there a problem?
Contact a Practice-It administrator.