Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860
Building Triangles - Huben's Wiki

Building Triangles

From Huben's Wiki
Jump to: navigation, search
(Created page with "Your assignment is to build three classes: Point, Triangle, and TestTriangle. Two of them will have toString() methods. These methods are used by println() if you try to displa...")
 
Line 4: Line 4:
  
 
Class Point will have:
 
Class Point will have:
* two double variables, x and y.
+
* two double fields, x and y.
 +
* a two argument constructor for setting the fields.
 
* nobody else should be able to look at or change those variables except with accessor or modifier methods (that you must write.)
 
* nobody else should be able to look at or change those variables except with accessor or modifier 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.
+
* a toString() method that has no arguments and returns a String showing the point as a coordinate pair such as (9,3).
  
 
Class Triangle will have:
 
Class Triangle will have:
* three Point variables: a, b and c.  They represent the vertex points.
+
* an array of three Point variables.  They represent the vertex points.
* anybody should be able to look at or change those variables.
+
* a constructor that takes 3 Points as arguments.
* a toString method that has no arguments and returns a string describing the Triangle by its three points.
+
* nobody should be able to look at or change those points.
* a perimeter method that anybody can use which returns the perimeter of the Triangle.
+
* 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.
* an area method that anybody can use, [[http://www.mathopenref.com/coordtrianglearea.html which uses this formula.]]  Remember that the functions you'll need are in class Math.
+
* a perimeter() method that anybody can use which returns the perimeter of the Triangle.
 +
* an area() method that anybody can use, [[http://www.mathopenref.com/coordtrianglearea.html which uses this 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.
  
Class TestTriangle will have
+
Class TestTriangle will have a main() that should:
* have a makeTriangle() method that:
+
* create at least three triangles, all with different points.
** has three arguments which are the three vertex points.
+
* print the triangles.
** create a triangle and assign these points to the Triangle.
+
* print the sum of the perimeters and the sum of the areas of the triangles.
** prints a description of the triangle created:
+
*** the three points
+
*** the side lengths
+
*** the perimeter
+
*** the area
+
** return the Triangle created.
+
* a main() that should:
+
** create three triangles, all with different points.
+
** print the sum of the perimeters and the sum of the areas of the three triangles.
+

Revision as of 15:07, 18 October 2012

Personal tools
translate