Program
Program
using System.IO;
using SplashKitSDK;
namespace ShapeCalculator
{
public class Program
{
private enum ShapeKind
{
Square,
Triangle,
Circle,
Trapezium,
Rectangle
}
while (true)
{
int choice = GetValidatedChoice();
if (shape != null)
{
Console.WriteLine($"Area: {shape.CalculateArea()}");
Console.WriteLine($"Perimeter:
{shape.CalculatePerimeter()}");
if (response.ToLower() == "yes")
{
Console.Write("Enter the filename to save: ");
string fileName = Console.ReadLine();
ShapeSaver saver = new
ShapeSaver($"SavedDrawings/{fileName}.txt");
saver.SaveShape(shape);
Console.WriteLine("Shape saved successfully.");
}
}
}
}
case ShapeKind.Triangle:
shape = new Triangle();
double baseLength =
InputValidator.GetValidatedDouble("Enter the base
length: ");
double height =
InputValidator.GetValidatedDouble("Enter the height:
");
((Triangle)shape).Base = isInches ?
UnitConverter.InchesToCentimeters(baseLength) :
baseLength;
((Triangle)shape).Height = isInches ?
UnitConverter.InchesToCentimeters(height) : height;
break;
case ShapeKind.Circle:
shape = new Circle();
double radius =
InputValidator.GetValidatedDouble("Enter the radius:
");
((Circle)shape).Radius = isInches ?
UnitConverter.InchesToCentimeters(radius) : radius;
break;
case ShapeKind.Trapezium:
shape = new Trapezium();
double base1 = InputValidator.GetValidatedDouble("Enter
the first base length: ");
double base2 = InputValidator.GetValidatedDouble("Enter
the second base length: ");
double trapeziumHeight =
InputValidator.GetValidatedDouble("Enter the height:
");
((Trapezium)shape).Base1 = isInches ?
UnitConverter.InchesToCentimeters(base1) : base1;
((Trapezium)shape).Base2 = isInches ?
UnitConverter.InchesToCentimeters(base2) : base2;
((Trapezium)shape).Height = isInches ?
UnitConverter.InchesToCentimeters(trapeziumHeight) :
trapeziumHeight;
break;
case ShapeKind.Rectangle:
shape = new Rectangle();
double width = InputValidator.GetValidatedDouble("Enter
the width: ");
double rectangleHeight =
InputValidator.GetValidatedDouble("Enter the height:
");
((Rectangle)shape).Width = isInches ?
UnitConverter.InchesToCentimeters(width) : width;
((Rectangle)shape).Height = isInches ?
UnitConverter.InchesToCentimeters(rectangleHeight) :
rectangleHeight;
break;
}
return shape;
}
shape.Draw();
SplashKit.RefreshScreen();
}
window.Close();
}
}
}