A Triangle Class That Uses Heron's Formula

advertisement
A Triangle Class That Uses Heron's Formula
Objective: Write a Java class that uses the Math class. Write a Triangle class and a TriangleTester to test the class.
Heron's Formula is a method for calculating the area of a triangle when you know the lengths of all three sides. Let a,b,c be the lengths of the sides of a triangle. The area is given by:
a+b+c
. A= √ s (s−a)(s−b)(s−c) where s is half the perimeter, or 2
Write a Triangle class with data fields for sides a, b, and c. Write accessors, “getters”, and mutators, “setters”, for all of the data fields. Write a method so that a Triangle can find its area using Heron's formula. Another method should be written to find its perimeter.
Write a TriangleTester class that tests all of the methods in the Triangle class. Create a couple of Triangles and make sure they can tell you the correct area and perimeter. Make sure you test all the “getters” and “setters”. Rubric: • Comments in the Program 20%
• Fulfills Objective in the "Objective" line above 40%
• Executes without Errors and with Correct Results 40%
Download