-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathShapeService.cs
35 lines (29 loc) · 1.08 KB
/
ShapeService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace CSharp.Tutorials.CodeRefactoring.Samples
{
class ShapeService
{
public static void CalculateAreas()
{
Console.WriteLine("Calculating areas before refactoring...");
double rectangleArea = CalculateRectangleArea(5, 10);
Console.WriteLine("Area of rectangle: " + rectangleArea);
double circleArea = CalculateCircleArea(7);
Console.WriteLine("Area of circle: " + circleArea);
double triangleArea = CalculateTriangleArea(3, 4, 5);
Console.WriteLine("Area of triangle: " + triangleArea);
}
static double CalculateRectangleArea(double length, double width)
{
return length * width;
}
static double CalculateCircleArea(double radius)
{
return Math.PI * radius * radius;
}
static double CalculateTriangleArea(double baseLength, double height, double side)
{
double s = (baseLength + height + side) / 2;
return Math.Sqrt(s * (s - baseLength) * (s - height) * (s - side));
}
}
}