Skip to content

Latest commit

 

History

History
94 lines (51 loc) · 3.11 KB

Triangle.md

File metadata and controls

94 lines (51 loc) · 3.11 KB

Documentation

public class Triangle

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
Area and perimeter of the triangle`are calculated, too.
  • Author: Mikko Rusama, SoberIT
  • Version: 26.8.2004

public Triangle(int s1, int s2, int s3)

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.

public Triangle setSideLengths(int s1, int s2, int s3)

Sets the lenghts of the sides of this triangle.

  • Parameters:
    • s1 — length of the side1
    • s2 — length of the side2
    • s3 — length of the side3
  • Returns: a reference to this triangle.

public String getSideLengths()

Gets the side lenghts.

  • Returns: a comma separated list of side lengths

public int getPerimeter()

Gets the perimeter of the triangle.

  • Returns: -1 if input values are invalid, otherwise the perimeter.

public double getArea()

Gets the area of the triangle.

  • Returns: area of the triangle, -1.0 if triangle is impossible.

public String classify()

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.

public boolean isIsosceles()

Checks if the triangle is isosceles. Note: isosceles triangle may also be equilateral and right-angled.

  • Returns: true if two sides have equal length

public boolean isEquilateral()

Checks if the triangle is equilateral.

  • Returns: true if all three sides have equal length.

public boolean isRightAngled()

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.

public boolean isScalene()

Checks if the triangle is scalene.

  • Returns: true if all sides different lengths, no right angles.

public boolean isImpossible()

Checks whether the given side lengths form a valid triangle.

  • Returns: true if the given side lenghts do not form a triangle.

public static void main(String[] args)

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.

References

This doc was generated by https://delight-im.github.io/Javadoc-to-Markdown/ from Triangle.java.