1. Refer to Exercise 16.3. Accomplish the same task, but write a method:
private double interest(double initial,
double perYear)
which returns the interest. Add exception handling to the method to check that all the values are positive. The method header should use throws with a NumberFormatException, and the body should incorporate a throw statement.
2. If you know the length of the three sides of a triangle, the area can be calculated by:
area = Math.sqrt(s * (s – a) * (s – b) * (s – c));
where:
s = (a + b + c) / 2;
Write a method for calculating and returning the area. Make it throw an exception when the three lengths cannot form a triangle.
Write a calling method for your area method, which catches your exception.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here