Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

What key control concept was missing at Argus Productions?

Answered: 1 week ago