How do I throw an exception such that it will output “Calculation failed, there is no change between x1 and x2” if my slope’s denominator is 0…The following block is a method within a class file.
public double getSlope() {
double rise = p2.getY() - p1.getY();
double run = p2.getX() - p1.getX();
double slope = rise / run;
return slope;
}
I’m outputting the results to my Testing file, or driver class containing a main method.
1 Answer