Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //ShapeBase shape = new ShapeBase();
            Triangle triangle = new Triangle(3, 4, 5);

            Console.WriteLine(triangle.Name);
            Console.WriteLine(triangle.GetPerimeter());
            Console.WriteLine(triangle.GetSquare());
            IsoscelesTriangle triangle2 = new IsoscelesTriangle(5, 4);

            Console.WriteLine(triangle2.Name);
            Console.WriteLine(triangle2.GetPerimeter());
            Console.WriteLine(triangle2.GetSquare());
            EquilateralTriangle triangle3 = new EquilateralTriangle(3);

            Console.WriteLine(triangle3.Name);
            Console.WriteLine(triangle3.GetPerimeter());
            Console.WriteLine(triangle3.GetSquare());
            RectangularTriangle triangle4 = new RectangularTriangle(3, 4);

            Console.WriteLine(triangle4.Name);
            Console.WriteLine(triangle4.GetPerimeter());
            Console.WriteLine(triangle4.GetSquare());
            Console.ReadKey();
        }
        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));
        }
Exemplo n.º 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("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;
                }
            }
        }