Triangle. The main function takes 3 positive whole-number lengths to be typed in as command line arguments. The program responds with a description of the triangle, as follows:
- equilateral - if all three sides have equal length
- isosceles - if two sides have equal length
- right-angled - if one angle is a right angle
- scalene - all sides different lengths, no right angles
- impossible - if the given side lengths do not form a triangle
- Author: Mikko Rusama, SoberIT
- Version: 26.8.2004
Constuctor (without error checking)
- Parameters:
s1
— length of the side1 as an integer.s2
— length of the side2 as an integer.s3
— length of the side3 as an integer.
Sets the lenghts of the sides of this triangle.
- Parameters:
s1
— length of the side1s2
— length of the side2s3
— length of the side3
- Returns: a reference to this triangle.
Gets the side lenghts.
- Returns: a comma separated list of side lengths
Gets the perimeter of the triangle.
- Returns: -1 if input values are invalid, otherwise the perimeter.
Gets the area of the triangle.
- Returns: area of the triangle, -1.0 if triangle is impossible.
Classifies the triangle. Possible types, returned as a string, are:
- equilateral - if all three sides have equal length
- isosceles - if two sides have equal length
- right-angled - if one angle is a right angle
- scalene - all sides different lengths, no right angles
- impossible - if the lengths can't form a triangle
- Returns: type of the triangle as a string.
Checks if the triangle is isosceles. Note: isosceles triangle may also be equilateral and right-angled.
- Returns: true if two sides have equal length
Checks if the triangle is equilateral.
- Returns: true if all three sides have equal length.
Checks if the triangle is right-angled. Note: right-angled triangle may also be isosceles.
- Returns: true if one angle is a right angle, otherwise false.
Checks if the triangle is scalene.
- Returns: true if all sides different lengths, no right angles.
Checks whether the given side lengths form a valid triangle.
- Returns: true if the given side lenghts do not form a triangle.
Usage: java Quadrangle <side1:int> <side2:int> <side3:int>
Main method is only used for testing purposes, no unit tests need to be written for this method.
This doc was generated by https://delight-im.github.io/Javadoc-to-Markdown/ from Triangle.java.