Esempio n. 1
0
        static void Main(string[] args)
        {
            Action <string, int, int> displaySize = (a, b, c) => Console.WriteLine(string.Format("{0} has perimiter {1}, area {2}", a, b, c));

            IShape box = new Rectangle();

            IShape myThing = box; // or = circle; we shouldn't care from this point on.

            displaySize(myThing.Type(), myThing.Perimiter(), myThing.Area());

            Action myAction = myThing.Grow; // or .Shrink, we don't care

            displaySize(myThing.Type(), myThing.Perimiter(), myThing.Area());

            var circle = CreateAndDoAction <Circle>(shape => {
                shape.Grow();
                shape.Shrink();
            });

            var rectangle = CreateAndDoAction <Rectangle>(ShrinkRectangle);

            displaySize(myThing.Type(), myThing.Perimiter(), myThing.Area());

            //we don't care what the thing or the action is, do it twice.
            PerformTwice(myAction);
            displaySize(myThing.Type(), myThing.Perimiter(), myThing.Area());

            Console.Read();
        }
 public int CompareTo(IShape obj)
 {
     if (obj.Area() > Area())
     {
         return(-1);
     }
     else if (obj.Area() == Area())
     {
         return(0);
     }
     return(1);
 }
Esempio n. 3
0
 private void AssertArea(int expected, IShape actualShape)
 {
     if (actualShape.Area() != expected)
     {
         throw new Exception("Wrong area!");
     }
 }
        static void IShapeExample()
        {
            Console.WriteLine("Press\n1 for Rectangle\n2 for Triangle\n3 for Circle");
            var item = Convert.ToInt32(Console.ReadLine());

            switch (item)
            {
            case 1:
                s1 = new Rectangle();
                break;

            case 2:
                s1 = new Triangle();
                break;

            case 3:
                s1 = new Circle();
                break;

            default:
                break;
            }

            s1.GetInput();
            s1.Area();
            s1.Perimeter();
        }
        public static void InertfaceExample()
        {
            Console.WriteLine("1 for Rectangle\n2 for Square\n3 for Circle");
            var choice = Console.ReadLine();

            switch (choice)
            {
            case "1":
                shape = new Rectangle();
                break;

            case "2":
                shape = new Square();
                break;

            case "3":
                shape = new Circle();
                break;

            default:
                break;
            }
            shape.GetInput();
            shape.Area();
            shape.Perimeter();
        }
Esempio n. 6
0
        public void EmptyRectangle_NoArea()
        {
            sut = new Rectangle(0, 0);

            Assert.AreEqual(0, sut.Width);
            Assert.AreEqual(0, sut.Height);

            Assert.AreEqual(0, sut.Area());
        }
        public void Rectangle_TestGettingArea()
        {
            var topLeft = new Point();

            topLeft.SetCartesian(3, 3);
            Rectangle = new Rectangle(topLeft, 4, 4);

            var expected = Math.Round(16.0, 4);

            Assert.AreEqual(expected, Math.Round(Rectangle.Area(), 4));
        }
Esempio n. 8
0
            public void Square_TestGettingArea()
            {
                var center = new Chapter06.Models.Point();

                center.SetCartesian(3, 3);
                Square = new Square(center, 4);

                var expected = Math.Round(16.0, 4);

                Assert.AreEqual(expected, Math.Round(Square.Area(), 4));
            }
Esempio n. 9
0
        public void Circle_TestGettingArea()
        {
            var center = new Point();

            center.SetCartesian(3, 3);
            Circle = new Circle(center, 4);

            var expected = Math.Round(50.2654824574367, 4);

            Assert.AreEqual(expected, Math.Round(Circle.Area(), 4));
        }
Esempio n. 10
0
        /// <summary>
        /// Gets area of IShape object
        /// </summary>
        /// <param name="shape"></param>
        /// <returns>float</returns>
        public float GetArea(IShape shape)

        {
            float result = 0;

            if (shape != null)
            {
                result = shape.Area();
            }

            return(result);
        }
Esempio n. 11
0
        public string CalculateAV(string radius, string side, string side1, string side2, string height, string currentShape, string currentOperation)
        {
            try
            {
                switch (currentShape)
                {
                case "Circle":
                    _shape = new Circle()
                    {
                        Radius = decimal.Parse(radius)
                    };
                    break;

                case "Square":
                    _shape = new Square()
                    {
                        Side = decimal.Parse(side)
                    };
                    break;

                case "Rectangle":
                    _shape = new RectangleShape()
                    {
                        Side1 = decimal.Parse(side1), Side2 = decimal.Parse(side2), Height = decimal.Parse(height)
                    };
                    break;

                default:
                    break;
                }
                decimal res = 0m;
                switch (currentOperation)
                {
                case "Area":
                    res = _shape.Area();
                    break;

                case "Volume":
                    res = _shape.Volume();
                    break;

                default:
                    break;
                }

                return(res.ToString());
            }
            catch (Exception ex)
            {
                return("-1");
            }
        }
Esempio n. 12
0
        public void TestCircleArea()
        {
            //Arrange
            shape = new Circle(10);
            double actualResult, expectedResult;

            //Act
            actualResult   = shape.Area();
            expectedResult = 314.0;

            //Assert
            Assert.Equal(expectedResult, actualResult);
        }
Esempio n. 13
0
        public void TestSquareArea()
        {
            //Arrange
            shape = new Square(10);
            double actualResult, expectedResult;

            //Act
            actualResult   = shape.Area();
            expectedResult = 100;

            //Assert
            Assert.Equal(expectedResult, actualResult);
        }
Esempio n. 14
0
        public void TestTriangleArea()
        {
            //Arrange
            shape = new Triangle(10, 20);
            double actualResult, expectedResult;

            //Act
            actualResult   = shape.Area();
            expectedResult = 100.0;

            //Assert
            Assert.Equal(expectedResult, actualResult);
        }
        public static void Main()
        {
            IShape shape1 = ShapeFactory.CreateShape("square", 4);

            Console.WriteLine("Shape Area: " + shape1.Area());
            Console.WriteLine("Shape Perimeter: " + shape1.Perimeter());

            IShape shape2 = ShapeFactory.CreateShape("circle", 3);

            Console.WriteLine("Shape Area: " + shape2.Area());
            Console.WriteLine("Shape Perimeter: " + shape2.Perimeter());

            Console.ReadLine();
        }
Esempio n. 16
0
        public DiffuseAreaLight(Transform lightToWorld,
                                IMedium mediumInterface,
                                Spectrum Lemit,
                                int nSamples,
                                IShape shape,
                                bool twoSided = false)
            : base(lightToWorld, mediumInterface, nSamples)
        {
            _mediumInterface = mediumInterface;
            _lemit           = Lemit;
            _shape           = shape;
            _twoSided        = twoSided;
            _area            = shape.Area();

            // TODO: Check for scale
        }
Esempio n. 17
0
        private void Display(IShape cr)
        {
            string[]     items = { cr.GetType().Name,
                                   cr.R.ToString("f3"),
                                   cr.L.ToString("f3"),
                                   cr.W.ToString("f3"),
                                   cr.Perimeter().ToString("f3"),
                                   cr.Area().ToString("f3"),
                                   cr.Volume().ToString("f3") };
            ListViewItem lvi = new ListViewItem(items);

            // add the row to the listview
            listView1.Items.Add(lvi);
            // making the last item visible
            listView1.EnsureVisible(listView1.Items.Count - 1);
        }
Esempio n. 18
0
        public static void Main()
        {
            ShapeFactory shape_factory = new SquareFactory();

            IShape shape1 = shape_factory.GetShape(4);

            Console.WriteLine("Shape Area: " + shape1.Area());
            Console.WriteLine("Shape Perimeter: " + shape1.Perimeter());

            shape_factory = new CircleFactory();
            IShape shape2 = shape_factory.GetShape(3);

            Console.WriteLine("Shape Area: " + shape2.Area());
            Console.WriteLine("Shape Perimeter: " + shape2.Perimeter());

            Console.ReadLine();
        }
Esempio n. 19
0
        static void Main(string[] args)
        {
            bool isOver = false;

            Console.WriteLine("Area and Perimeter Calculator for Shapes");
            Console.WriteLine("----------------------------------------");

            while (!isOver)
            {
                bool isValidInput = false;

                while (!isValidInput)
                {
                    Console.Write("\nPlease enter the name of the shape you'd like to calculate for (circle, square or triangle): ");
                    string input = Console.ReadLine().ToLower();

                    if (input == "circle" || input == "square" || input == "triangle")
                    {
                        ShapeFactory factory = new ShapeFactory();
                        IShape       shape   = factory.GetShape(input);

                        if (shape.Area() == 0 || shape.Perimeter() == 0)
                        {
                            Console.WriteLine("\nThe measurement(s) that you entered is/are not valid.");
                        }
                        else
                        {
                            Console.WriteLine("\nThe area of your {0} is: {1:0.00} square inches", input, shape.Area());
                            Console.WriteLine("\nThe perimeter of your {0} is: {1:0.00} inches", input, shape.Perimeter());
                            isValidInput = true;
                        }
                    }
                    else
                    {
                        Console.WriteLine("\nThat was not a valid response.  Please try again.");
                    }
                }

                Console.Write("\nWould you like to calculate for another shape? Y/N ");
                if (Console.ReadLine().ToUpper() == "N")
                {
                    isOver = true;
                }
            }
        }
Esempio n. 20
0
        private static string ShapeAreaResponse(IShape shape)
        {
            string shapeClassName = shape.GetType().ToString();
            int    lastChars      = shapeClassName.LastIndexOf('.') + 1;
            string shapeName      = shapeClassName.Substring(lastChars, shapeClassName.Length - lastChars);
            var    response       = string.Format("The area of the {0} is {1}", shapeName, shape.Area());

            return(response);
        }
Esempio n. 21
0
        public static void AssertShapeArea(IShape shape, double areaResult)
        {
            var area = shape.Area();

            Assert.IsTrue(Math.Abs(area - areaResult) < Tolerance);
        }
Esempio n. 22
0
 public double CalculateArea(IShape shape)
 {
     return(shape.Area());
 }
Esempio n. 23
0
 public static double Area(IShape shape)
 {
     return(shape.Area());
 }
Esempio n. 24
0
 public double GetArea(IShape shape)
 {
     return(shape.Area());
 }
Esempio n. 25
0
        public void SimpleRectangle_CalculateArea()
        {
            sut = new Rectangle(5, 5);

            Assert.AreEqual(25, sut.Area());
        }
Esempio n. 26
0
 public bool BiggerThan(IShape that) => this.Area() >= that.Area();
Esempio n. 27
0
 public static void PrintShape(IShape shape)
 {
     Console.WriteLine(shape.Area());
 }
 /// <summary>
 /// よくある interface のサンプルコード。
 /// 図形の面積と周長を Console 出力。
 /// </summary>
 /// <param name="s"></param>
 static void Output(IShape s)
 {
     Console.WriteLine("面積: {0}", s.Area());
     Console.WriteLine("周長: {0}", s.Perimeter());
 }