Main Page → Problems → Solve a Problem
Exercise 8.3: slope
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
}
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.
Show/Hide Description
Re-indent