Question: 1. Complete the PerimeterCalculator program below that prompts the user for the lengths of two sides of a right triangle (not the hypotenuse), and then

 1. Complete the PerimeterCalculator program below that prompts the user for

1. Complete the PerimeterCalculator program below that prompts the user for the lengths of two sides of a right triangle (not the hypotenuse), and then calculates and outputs the perimeter of the triangle. public class PerimeterCalculator { public static void main (String[] args) { // Add code here System.out.printf("Perimeter: %.2f ", calculatePerimeter(a, b)); } public static double calculatePerimeter(int a, int b) { // Add code here } } o Prompt the user for the lengths of sides a and b. Output Invalid value and exit the program if the length of either side is less than or equal to 0. Do this before calling the calculate Perimeter() method. You can use the statement: System.exit(1); to exit the program after printing "Invalid value". Note: You can assume that the user will type in values of the appropriate type. Throw an IllegalArgumentException with the message "Invalid value" at the beginning the calculate Perimeter() method, if a orb is less than or equal to 0. You must do this parameter validation even though your main method should not call this method with an invalid parameter value because some other program could call this method using the following method call: PerimeterCalculator.calculate Perimeter(0, 1); Provide "javadoc" for the class, methods, and exception (throws tag). o Here are some examples of how your program should execute (your prompts and error message must exactly match those given in these sample program executions): $ java PerimeterCalculator Side a: 3 Side b: 4 Perimeter: 12.00 $ java PerimeterCalculator Side a: 0 Invalid value $ java PerimeterCalculator Side a: 2 Side b: 2 Perimeter: 6.83

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!