Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace RsAssginment2Triangle
- {
- /// <summary>
- /// Class responsable to know the rules of a triangle
- /// </summary>
- public static class TriangleSolver
- {
- /// <summary>
- /// Value used to identify a scalene triangle
- /// </summary>
- public const string SCALENE = "scalene";
- /// <summary>
- /// Value used to identify a isosceles triangle
- /// </summary>
- public const string ISOSCELES = "isosceles";
- /// <summary>
- /// Value used to identify a equilateral triangle
- /// </summary>
- public const string EQUILATERAL = "equilateral";
- /// <summary>
- /// Value used to identify a non triangle dimensions given
- /// </summary>
- public const string NON_TRIANGULE = "non triangle";
- /// <summary>
- /// Method that analyze if three dimensions form a valid triangle and identify which type
- /// of triangle is it.
- /// </summary>
- /// <param name="a">First dimension</param>
- /// <param name="b">Second dimension</param>
- /// <param name="c">Third dimension</param>
- /// <returns>The name of the triangle type or "non triangle"</returns>
- public static string Analyze(int a, int b, int c)
- {
- string result;
- if (
- (a + b > c && a + c > b && b + c > a)
- &&
- (a > 0 && b > 0 && c > 0))
- {
- if(a == b && b == c)
- {
- result = EQUILATERAL;
- }else if (a == b || b == c)
- {
- result = ISOSCELES;
- }else
- {
- result = SCALENE;
- }
- }else
- {
- result = NON_TRIANGULE;
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement