
Assignment 09Task
Repeat A02, only this time using static methods and user input.
Textbook: 4.4; 10.1  10.3 StepsWrite a program that asks the user to enter a base and height of a right triangle, and then print out its details. Print out both the base and height the user entered, as well as the hypotenuse, the perimeter, the area, and the slope of the hypotenuse. See A02 if you need to review the necessary formulas. Step 1: Methods
It would be nice to be able to reuse these calculations for other triangles, much in the way you reuse the methods written in the
Remember that, as separate methods, these definitions will be in your class but outside of the main method. Also, you can name the parameters whatever you wantthey could be However, the name of the method does matter. Make sure you name the methods exactly as shown, as Tamarin will be trying to call them, passing different values than you used when you call them from your main method.
You will need to provide the {bodies} for these methods that do the appropriate calculation in each case and returns the result. You may be able to reuse one method from another; for example, you can call
Clarification (26 Sept): As mentioned, the methods should return
their
results. They should not do any printing themselves; all your printing
will occur only in Step 2: Main methodCall the four methods you wrote from your main method. Again, the methods will now perform the calculations for you, so you don't need to repeat them in main. Also, make sure the user's input is valid. Use a try/catch block so that your program ends gracefully (rather than crashing) if the user enters a String when you ask for a number. Also, make sure all lengths entered are greater than 0. (You can either check each length as it is entered, or check both at the same time if you want to.) Sample OutputD:\TA\grading\A09>java ZtomaszeA09 This program provides the details of a right triangle. Enter the length of the triangle's base: 12 Enter the length of the triangle's height: feet Sorry, but you must enter a valid decimal number. D:\TA\grading\A09>java ZtomaszeA09 This program provides the details of a right triangle. Enter the length of the triangle's base: 1000.04 Enter the length of the triangle's height: 90 Sorry, a triangle's sides must each have a length greater than 0. D:\TA\grading\A09>java ZtomaszeA09 This program provides the details of a right triangle. Enter the length of the triangle's base: 7.5 Enter the length of the triangle's height: 18 Base: 7.5 Height: 18.0 Hypotenuse: 19.5 Perimeter: 45.0 Area: 67.5 Slope of hypotenuse: 2.4 What to Submit
Upload your Grading [4 points]
FAQs

~ztomasze Index :
TA Details: ICS111:
Assignment 9 http://www2.hawaii.edu/~ztomasze 
Last Edited: 23 Sep 2008 ©2008 by Z. Tomaszewski. 