/// <summary>
        /// Business method to calculate Traingle area
        /// </summary>
        /// <param name="sideA"></param>
        /// <param name="sideB"></param>
        /// <param name="sideC"></param>
        /// <returns>Traingle Type</returns>
        public double CalculateTriangleArea(model.Triangle triangle)
        {
            if (triangle != null)
            {
                _sideA = triangle.SideOne;
                _sideB = triangle.SideTwo;
                _sideC = triangle.SideThree;
            }
            double area = 0;

            try
            {
                // Check whether the traingle is valid
                if (isValidTriangle())
                {
                    area = _triangleUtility.CalculateArea(triangle);
                }
                else
                {
                    throw new Exception("InvalidTriangleException");
                }

                return(area);
            }
            catch (Exception ex) {
                throw ex;
            }
        }
示例#2
0
        /// <summary>
        /// Method to calculate area of triangle
        /// </summary>
        /// <param name="triangle">triangle object with all three sides</param>
        /// <returns>Area of triangle</returns>
        public double CalculateArea(model.Triangle triangle)
        {
            double area = 0;

            // Calculate Perimeter
            var perimeter = (triangle.SideOne + triangle.SideTwo + triangle.SideThree) / 2;

            // Calculate area
            area = Math.Sqrt(perimeter * (perimeter - triangle.SideOne) * (perimeter - triangle.SideTwo) * (perimeter - triangle.SideThree));

            // Return area
            return(area);
        }