예제 #1
0
        public void EquilateralTest(int sideLength, double area, double perimeter)
        {
            Equilateral equilateral = new Equilateral(sideLength);

            Assert.AreEqual(area, Math.Round(equilateral.GetArea(), 2));
            Assert.AreEqual(perimeter, Math.Round(equilateral.GetPerimeter(), 2));
        }
예제 #2
0
        public void iShapeCalc_test_Equilateral(double side1, double areaExpected, double perExpected)
        {
            var equil     = new Equilateral("red", side1);
            var equilArea = equil.GetArea(side1);
            var equilPer  = equil.GetPerimeter(side1);

            Assert.AreEqual(areaExpected, equilArea);
            Assert.AreEqual(perExpected, equilPer);
        }
예제 #3
0
        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("5. Circle");
                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?");
                    double side   = GetNum();
                    Square square = new Square(side);
                    square.Colour = colour;
                    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?");
                    double width = GetNum();
                    Console.Clear();
                    Console.WriteLine($"You are making a {colour} rectangle with width: {width}");
                    Console.WriteLine("How tall is it?");
                    double    height    = GetNum();
                    Rectangle rectangle = new Rectangle(width, height);
                    rectangle.Colour = colour;
                    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?");
                    double      side = GetNum();
                    Equilateral equilateralTriangle = new Equilateral(side);
                    equilateralTriangle.Colour = colour;
                    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?");
                    double width = GetNum();
                    Console.Clear();
                    Console.WriteLine($"You are making a {colour} right angle triangle with base: {width}");
                    Console.WriteLine("How tall is it?");
                    double     height             = GetNum();
                    RightAngle rightAngleTriangle = new RightAngle(width, height);
                    rightAngleTriangle.Colour = colour;
                    rightAngleTriangle.SetHypotenuse();
                    Console.Clear();
                    Console.WriteLine($"You created a {colour} right angle triangle with base: {width}, height: {height}, hypotenuse: {rightAngleTriangle.Side3Length}, an area of {rightAngleTriangle.GetArea()} and a perimeter of {rightAngleTriangle.GetPerimeter()}");
                    Console.ReadKey();
                }
                break;

                case "5":
                {
                    Console.Clear();
                    Console.WriteLine("You are making a circle");
                    Console.WriteLine("What colour is it?");
                    string colour = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine($"You are making a {colour} circle");
                    Console.WriteLine("What is its radius?");
                    double radius = GetNum();
                    Circle circle = new Circle();
                    circle.Radius = radius;
                    circle.Colour = colour;
                    Console.Clear();
                    Console.WriteLine($"You created a {colour} circle with radius: {radius}, an area of {circle.GetArea()} and a perimeter of {circle.GetPerimeter()}");
                    Console.ReadKey();
                }
                break;

                case "e":
                {
                    running = false;
                }
                break;

                default:
                    continue;
                }
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            WL("1 - Quadrilateral");
            WL("2 - Triangle");
            WL("3 - Circle");
            space();

            ConsoleKeyInfo Menu1;

            Menu1 = Console.ReadKey();
            ////////////////// Quadrilateral //////////////////
            if (Menu1.Key == ConsoleKey.D1)
            {
                space();
                WL("Input Color");
                space();
                string UColor = Console.ReadLine();
                space();
                WL("1 - Square");
                WL("2 - Rectangle");
                space();
                ConsoleKeyInfo Menu2;
                Menu2 = Console.ReadKey();
                ////////////////// Square //////////////////
                if (Menu2.Key == ConsoleKey.D1)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        Square newSq = new Square(UColor, Uside1);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newSq.GetArea(Uside1));
                        WL("Perimeter: " + newSq.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                ////////////////// Rectangle //////////////////
                if (Menu2.Key == ConsoleKey.D2)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        WL("Input side length 2");
                        double Uside2    = double.Parse(Console.ReadLine());
                        string Uside2Str = Uside2.ToString();
                        space();
                        if (Uside2 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside2Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        Rectangle newRec = new Rectangle(UColor, Uside1, Uside2);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newRec.GetArea(Uside1));
                        WL("Perimeter: " + newRec.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                Console.ReadKey();
            }
            ////////////////// Triangle //////////////////
            if (Menu1.Key == ConsoleKey.D2)
            {
                space();
                WL("Input Color");
                space();
                string UColor = Console.ReadLine();
                space();
                WL("1 - Equilateral");
                WL("2 - Right-Angled");
                space();
                ConsoleKeyInfo Menu2;
                Menu2 = Console.ReadKey();
                //////////////////  Equilateral //////////////////
                if (Menu2.Key == ConsoleKey.D1)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        Equilateral newEq = new Equilateral(UColor, Uside1);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newEq.GetArea(Uside1));
                        WL("Perimeter: " + newEq.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                ////////////////// Right-Angled //////////////////
                if (Menu2.Key == ConsoleKey.D2)
                {
                    try
                    {
                        space();
                        WL("Input side length 1");
                        double Uside1    = double.Parse(Console.ReadLine());
                        string Uside1Str = Uside1.ToString();
                        space();
                        int d;
                        if (Uside1 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside1Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        WL("Input side length 2");
                        double Uside2    = double.Parse(Console.ReadLine());
                        string Uside2Str = Uside2.ToString();
                        space();
                        if (Uside2 < 1)
                        {
                            throw (new InvalidIntException(""));
                        }
                        if (!int.TryParse(Uside2Str, out d))
                        {
                            throw (new InvalidDecException(""));
                        }
                        RightAngled newRA = new RightAngled(UColor, Uside1, Uside2);
                        newRA.SetHypotenuse(Uside1, Uside2);
                        space();
                        WL("Color: " + UColor);
                        WL("Area: " + newRA.GetArea(Uside1));
                        WL("Perimeter: " + newRA.GetPerimeter(Uside1));
                    }
                    catch (InvalidIntException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    catch (InvalidDecException e)
                    {
                        space();
                        WL(e.Message);
                    }
                    finally
                    {
                        WL("Thanks for using the app!");
                    }
                }
                Console.ReadKey();
            }
            ////////////////// Circle //////////////////
            if (Menu1.Key == ConsoleKey.D3)
            {
                try
                {
                    space();
                    WL("Input Color");
                    space();
                    string UColor = Console.ReadLine();
                    space();
                    WL("Input radius");
                    double URad    = double.Parse(Console.ReadLine());
                    string URadStr = URad.ToString();
                    int    d;
                    if (URad < 1)
                    {
                        throw (new InvalidIntException(""));
                    }
                    if (!int.TryParse(URadStr, out d))
                    {
                        throw (new InvalidDecException(""));
                    }
                    space();
                    Circle newCirc = new Circle(UColor, URad);
                    space();
                    WL("Color: " + UColor);
                    WL("Area: " + newCirc.GetArea(URad));
                    WL("Circumference: " + newCirc.GetPerimeter(URad));
                }
                catch (InvalidIntException e)
                {
                    space();
                    WL(e.Message);
                }
                catch (InvalidDecException e)
                {
                    space();
                    WL(e.Message);
                }
                finally
                {
                    WL("Thanks for using the app!");
                }
            }
            Console.ReadKey();
        }
 public void EquilateralTest(double side, double area, double peri)
 {
     equil = new Equilateral("Blue", side);
     Assert.AreEqual(area, equil.GetArea());
     Assert.AreEqual(peri, equil.GetPerimeter());
 }
예제 #6
0
 public void GetAreaTest(double input, double expected)
 {
     eq = new Equilateral(colour, input);
     Assert.AreEqual(expected, eq.GetArea());
 }