A Triangle will have 3 sides. The class will be able to keep track of the number of Triangle objects created. It will also hold the total of the perimeters of all the Triangle objects created. ï It will allow a client to create a Triangle, passing in integer values for the three sides into the Triangle constructor. If the values for the sides that are passed in do not represent a valid Triangle (read below for the requirements for a Triangle to be valid) , then all sides will be set to a value of 1. The constructor should add 1 to the count of the number of Triangles created. The constructor should call a method to calculate the perimeter and then add the perimeter for that object to an accumulator.
Class Triangle
ï A Triangle will have 3 sides. The class will be able to keep track of the number of Triangle objects created. It will also hold the total of the perimeters of all the Triangle objects created.
ï It will allow a client to create a Triangle, passing in integer values for the three sides into the Triangle constructor.
- If the values for the sides that are passed in do not represent a valid Triangle (read below for the requirements for a Triangle to be valid) , then all sides will be set to a value of 1.
- The constructor should add 1 to the count of the number of Triangles created.
- The constructor should call a method to calculate the perimeter and then add the perimeter for that object to an accumulator.
In addition to the constructor, the Triangle class must have the following methods that return a boolean value:
- isRight () - see note 1 below regarding Acute triangles.
- isAcute() - see note 1 below regarding Acute triangles.
- isObtuse() - see note 1 below regarding Obtuse triangles.
- isScalene() - no two sides are the same length
- isIsosceles() - exactly two sides are the same length
- isEquilateral() - all three sides are the same length
- isValid() - the sum of any two sides of a triangle must be greater than the third in order to represent a valid triangle. Also, no side may be 0 or negative.
- equals (Triangle t) – compares two Triangle objects to determine if they are equal. We will compare their perimeters to determine equality.
Additional methods in the Triangle class
- toString() – returns a String that specifies the values for the 3 sides of the triangle
- calcPerim() – calculate and return the perimeter of the object.
- addTotalPerim(). This method will call calc_perim() and add the perimeter for that object to an accumulator.
- reduceTotalPerim(). This method should subtract the perimeter for that object from the accumulator.
- Accessor methods for all properties.
- The Triangle object cannot assume that the values of the 3 sides are entered in any particular order. Think about what that means.
Be sure to specify proper visibility for all methods and properties
Note 1:
When given 3 triangle sides:
- to determine if the triangle is right
1) Square all 3 sides.
2) Sum the squares of the 2 shortest sides.
3) Compare this sum to the square of the 3rd side.
4) If equal then we have a right triangle
Note 2:
All methods MUST be well documented including formalized pre-conditions and post-conditions. Refer to document T-1_Design By Contract located in the testing folder in your Project 1 download for guidance.
Note 3:
Your Triangle and Circle classes MUST be written according to these specifications. Do not vary from those specs.

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









