Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace RsAssginment2Triangle
  8. {
  9.     /// <summary>
  10.     /// Class responsable to know the rules of a triangle
  11.     /// </summary>
  12.     public static class TriangleSolver
  13.     {
  14.         /// <summary>
  15.         /// Value used to identify a scalene triangle
  16.         /// </summary>
  17.         public const string SCALENE = "scalene";
  18.         /// <summary>
  19.         ///  Value used to identify a isosceles triangle
  20.         /// </summary>
  21.         public const string ISOSCELES = "isosceles";
  22.         /// <summary>
  23.         ///  Value used to identify a equilateral triangle
  24.         /// </summary>
  25.         public const string EQUILATERAL = "equilateral";
  26.         /// <summary>
  27.         ///  Value used to identify a non triangle dimensions given
  28.         /// </summary>
  29.         public const string NON_TRIANGULE = "non triangle";
  30.  
  31.         /// <summary>
  32.         /// Method that analyze if three dimensions form a valid triangle and identify which type
  33.         /// of triangle is it.
  34.         /// </summary>
  35.         /// <param name="a">First dimension</param>
  36.         /// <param name="b">Second dimension</param>
  37.         /// <param name="c">Third dimension</param>
  38.         /// <returns>The name of the triangle type or "non triangle"</returns>
  39.         public static string Analyze(int a, int b, int c)
  40.         {
  41.             string result;
  42.            
  43.             if (
  44.                 (a + b > c && a + c > b && b + c > a)
  45.                 &&
  46.                 (a > 0 && b > 0 && c > 0))
  47.             {
  48.                 if(a == b && b == c)
  49.                 {
  50.                     result = EQUILATERAL;
  51.                 }else if (a == b || b == c)
  52.                 {
  53.                     result = ISOSCELES;
  54.                 }else
  55.                 {
  56.                     result = SCALENE;
  57.                 }
  58.             }else
  59.             {
  60.                 result = NON_TRIANGULE;
  61.             }
  62.             return result;
  63.         }
  64.  
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement