https://github.com/hackvan/triangle-classification
https://github.com/hackvan/triangle-classification
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hackvan/triangle-classification
- Owner: hackvan
- License: other
- Created: 2018-07-12T18:40:45.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-12T18:52:19.000Z (almost 7 years ago)
- Last Synced: 2025-01-05T17:13:22.226Z (5 months ago)
- Language: Ruby
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Triangle
## Objectives
1. Define a custom error and use it.
## Instructions
* Write a `Triangle` class that accepts three arguments on initialization. Each argument is a length of one of the three sides of the triangle.
* Give your Triangles an instance method, `kind` that returns, as a symbol, its type. The valid types are:
1. `:equilateral`
2. `:isosceles`
3. `:scalene`
* The `kind` method should raise a custom error, `TriangleError` if the triangle is invalid. Check out the hint below to understand what makes a triangle invalid. Write a custom error class, `TriangleError` and inherit it from `StandardError`. This custom error class should be defined in the same file as the `Triangle` class, but outside of the class definition of `Triangle`. Like this:
```ruby
# lib/triangle.rbclass Triangle
# triangle codeclass TriangleError < StandardError
# triangle error code
end
end
```## Hint
The sum of the lengths of any two sides of a triangle always exceeds the length of the third side. This is a principle known as the _triangle inequality_.
Further, each side must be larger than 0.
## Resources
* [Exception Handling](http://www.skorks.com/2009/09/ruby-exceptions-and-exception-handling/)
* [Basic Mathematics](http://www.basic-mathematics.com/) - [Types of Triangles](http://www.basic-mathematics.com/types-of-triangles.html)View Triangle on Learn.co and start learning to code for free.