Triangle Lab
The purpose of this lab is to gain familiarity with basic Java programming.
Write an application that uses Heron's formula to compute the area of a triangle, given the length of each side, a, b, c:
area = sqrt (s (s - a) (s - b) (s-c))
where s is half the perimeter of the triangle.
Use the static method Math.random to generate a number between 0 and 1; multiply by 9 and add 1 to get a number x between 1 and 10. Then let the sides of the triangle be 3x, 4x, 5x. This will give a right triangle whose area can be easily computed and used to check our results.
Print the result as follows:
A triangle with sides 16.26861999087936, 21.691493321172477, 27.114366651465595
has area 176.44533093842637
Run the program several times.
Have Fun!
|