public void EquilateralTriangleTests(string color, float s1, float expArea, float expPer) { eq1 = new EquilateralTriangle(color, s1); //float area = 15.59f; //float perimeter = 18; Assert.AreEqual(Math.Round(expArea, 2), Math.Round(eq1.GetArea(), 2)); Assert.AreEqual(Math.Round(expPer, 2), Math.Round(eq1.GetPerimeter(), 2)); //area = 27.71f; //perimeter = 24; //Assert.AreEqual(Math.Round(area, 2), Math.Round(eq2.GetArea(), 2)); //Assert.AreEqual(Math.Round(perimeter, 2), Math.Round(eq2.GetPerimeter(), 2)); }
static void Main(string[] args) { bool running = true; while (running) { Console.Clear(); Console.WriteLine("Make a Shape!"); Console.WriteLine("1. Square"); Console.WriteLine("2. Rectangle"); Console.WriteLine("3. Equilateral Triangle"); Console.WriteLine("4. Right Angle Triangle"); Console.WriteLine("e. Exit"); switch (Console.ReadLine()) { case "1": { Console.Clear(); Console.WriteLine("You are making a square"); Console.WriteLine("What colour is it?"); string colour = Console.ReadLine(); Console.Clear(); Console.WriteLine($"You are making a {colour} square"); Console.WriteLine("What is its side length?"); int side = GetInt(); Square square = new Square(colour, side); Console.Clear(); Console.WriteLine($"You created a {colour} square with side length: {side}, an area of {square.GetArea()} and a perimeter of {square.GetPerimeter()}"); Console.ReadKey(); } break; case "2": { Console.Clear(); Console.WriteLine("You are making a rectangle"); Console.WriteLine("What colour is it?"); string colour = Console.ReadLine(); Console.Clear(); Console.WriteLine($"You are making a {colour} rectangle"); Console.WriteLine("How wide is it?"); int width = GetInt(); Console.Clear(); Console.WriteLine($"You are making a {colour} rectangle with width: {width}"); Console.WriteLine("How tall is it?"); int height = GetInt(); Rectangle rectangle = new Rectangle(colour, width, height); Console.Clear(); Console.WriteLine($"You created a {colour} rectangle with width: {width}, height: {height}, an area of {rectangle.GetArea()} and a perimeter of {rectangle.GetPerimeter()}"); Console.ReadKey(); } break; case "3": { Console.Clear(); Console.WriteLine("You are making an equilateral triangle"); Console.WriteLine("What colour is it?"); string colour = Console.ReadLine(); Console.Clear(); Console.WriteLine($"You are making a {colour} equilateral triangle"); Console.WriteLine("What is its side length?"); float side = GetFloat(); EquilateralTriangle equilateralTriangle = new EquilateralTriangle(colour, side); Console.Clear(); Console.WriteLine($"You created a {colour} equilateral triangle with side length: {side}, an area of {equilateralTriangle.GetArea()} and a perimeter of {equilateralTriangle.GetPerimeter()}"); Console.ReadKey(); } break; case "4": { Console.Clear(); Console.WriteLine("You are making a right angle triangle"); Console.WriteLine("What colour is it?"); string colour = Console.ReadLine(); Console.Clear(); Console.WriteLine($"You are making a {colour} right angle triangle"); Console.WriteLine("How wide is it?"); float width = GetFloat(); Console.Clear(); Console.WriteLine($"You are making a {colour} right angle triangle with base: {width}"); Console.WriteLine("How tall is it?"); float height = GetFloat(); RightAngleTriangle rightAngleTriangle = new RightAngleTriangle(colour, width, height); Console.Clear(); Console.WriteLine($"You created a {colour} right angle triangle with base: {width}, height: {height}, an area of {rightAngleTriangle.GetArea()} and a perimeter of {rightAngleTriangle.GetPerimeter()}"); Console.ReadKey(); } break; case "e": { running = false; } break; default: continue; } } }
static void Main(string[] args) { Square sq1; Rectangle rec1; RightAngleTriangle ra1; EquilateralTriangle eq1; Input t = new Input(); Console.WriteLine("Hello World!"); Console.WriteLine("A: Square, B: Rectangle, C: Equilateral, D: Right-Angled"); string input = Console.ReadLine(); //int s1; //int s2; int count = 0; //float t1; //float t2; //float t3; string tests; while (count == 0) { if (input == "A") { Console.WriteLine("Please enter required values"); Console.WriteLine("Please enter a colour"); tests = Console.ReadLine(); Console.WriteLine("Side 1: "); try { t.s1 = int.Parse(Console.ReadLine()); } catch (Exception ex) { if (ex is FormatException || ex is InvalidInput) { Console.WriteLine("Test: " + ex.Message); } } sq1 = new Square(tests, t.s1); Console.WriteLine(sq1.GetArea()); Console.WriteLine(sq1.GetPerimeter()); } else if (input == "B") { Console.WriteLine("Please enter required values"); Console.WriteLine("Please enter a colour"); tests = Console.ReadLine(); try { Console.WriteLine("Side 1: "); t.s1 = int.Parse(Console.ReadLine()); Console.WriteLine("Side 2: "); t.s2 = int.Parse(Console.ReadLine()); } catch (Exception ex) { if (ex is FormatException || ex is InvalidInput) { Console.WriteLine("Test: " + ex.Message); } } rec1 = new Rectangle(tests, t.s1, t.s2); Console.WriteLine(rec1.GetArea()); Console.WriteLine(rec1.GetPerimeter()); } else if (input == "C") { Console.WriteLine("Please enter required values"); Console.WriteLine("Please enter a colour"); tests = Console.ReadLine(); Console.WriteLine("Side 1: "); try { t.t1 = float.Parse(Console.ReadLine()); } catch (Exception ex) { if (ex is FormatException || ex is InvalidInput) { Console.WriteLine("Test: " + ex.Message); } } eq1 = new EquilateralTriangle(tests, t.t1); Console.WriteLine(eq1.GetArea()); } else if (input == "D") { Console.WriteLine("Please enter required values"); Console.WriteLine("Please enter a colour"); tests = Console.ReadLine(); try { Console.WriteLine("Side 1: "); t.t1 = float.Parse(Console.ReadLine()); Console.WriteLine("Side 2: "); t.t2 = float.Parse(Console.ReadLine()); } catch (Exception ex) { if (ex is FormatException || ex is InvalidInput) { Console.WriteLine("Test: " + ex.Message); } } ra1 = new RightAngleTriangle(tests, t.t1, t.t2); Console.WriteLine(ra1.GetArea()); Console.WriteLine(ra1.GetPerimeter()); } else { Console.WriteLine("Invalid option, press any key to exit."); Console.ReadKey(true); } } Console.WriteLine("test"); Console.ReadKey(true); }