Building Triangles
From Huben's Wiki
Line 4: | Line 4: | ||
Class Point will have: | Class Point will have: | ||
− | * two double fields, x and y. | + | * two final double fields, x and y. |
* a two argument constructor for setting the fields. | * a two argument constructor for setting the fields. | ||
− | * nobody else should be able to look at or change those variables except with accessor | + | * nobody else should be able to look at or change those variables except with accessor methods (that you must write.) |
* a method named distance() that takes another point as an argument and finds the distance between the two points. | * a method named distance() that takes another point as an argument and finds the distance between the two points. | ||
* a toString() method that has no arguments and returns a String showing the point as a coordinate pair such as (9,3). | * a toString() method that has no arguments and returns a String showing the point as a coordinate pair such as (9,3). | ||
Line 16: | Line 16: | ||
* a sideLength() method that takes two integer arguments which are the indexes of two points in the array. Example: sideLength(0, 2). It should use the Point.distance() method to calculate the answer. | * a sideLength() method that takes two integer arguments which are the indexes of two points in the array. Example: sideLength(0, 2). It should use the Point.distance() method to calculate the answer. | ||
* a perimeter() method that anybody can use which returns the perimeter of the Triangle. | * a perimeter() method that anybody can use which returns the perimeter of the Triangle. | ||
− | * an area() method that anybody can use, | + | * an area() method that anybody can use, [http://www.mathopenref.com/coordtrianglearea.html which uses this formula] or [http://en.wikipedia.org/wiki/Heron%27s_formula Heron's formula]. Remember that the functions you'll need are in class Math. |
* a toString() method that has no arguments and returns a String describing the Triangle by its three points, its side lengths, its perimeter and its area. | * a toString() method that has no arguments and returns a String describing the Triangle by its three points, its side lengths, its perimeter and its area. | ||