Пример #1
14
        static void Main()
        {
            //creates a Triangle and calculates surface
            var triangle = new Triangle(3.2, 4.5);
            var triangleSurface = triangle.CalculateSurface();

            //creates a Rectangle and calculates surface
            var rectangle = new Rectangle(4, 12.3);
            var rectangleSurface = rectangle.CalculateSurface();

            //creates a Square and calculates surface
            var square = new Square(5);
            var squareSurface = square.CalculateSurface();

            //prints shapes and surfaces
            PrintShape(triangle);
            Console.WriteLine("Surface of the triangle is: {0}", triangleSurface);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine();

            PrintShape(rectangle);
            Console.WriteLine("Surface of the rectangle is: {0}", rectangleSurface);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine();

            PrintShape(square);
            Console.WriteLine("Surface of the square is: {0}", squareSurface);
            Console.WriteLine(new string('-', 30));
        }
Пример #2
1
 public void TestRectangleConstructor3()
 {
     // test that top and left are set by setter
         Shapes.Rectangle rect = new Shapes.Rectangle();
         rect.Top = 5;
         rect.Left= 3;
         Assert.AreEqual(5, rect.Top);
         Assert.AreEqual(3, rect.Left);
 }
 /// <summary>
 /// Demonstrate the usage of figures
 /// </summary>
 public static void Main()
 {
     Circle circle = new Circle(5);
     Console.WriteLine(circle);
     Rectangle rect = new Rectangle(2, 3);
     Console.WriteLine(rect);
 }
Пример #4
0
 public void TestRectangleConstructor2()
 {
     // test that top and left are set by constructor
     Shapes.Rectangle rect = new Shapes.Rectangle(5, 3);
     Assert.AreEqual(5, rect.Top);
     Assert.AreEqual(3, rect.Left);
 }
Пример #5
0
 public void TestRectangleConstructor2()
 {
     // test that top and left are set by constructor
         Shapes.Rectangle rect = new Shapes.Rectangle(5, 3);
         Assert.AreEqual(5, rect.Top);
         Assert.AreEqual(3, rect.Left);
 }
Пример #6
0
        public void RectangleWithXY()
        {
            var rectangle = new Rectangle(
                20, 20,
                30, 20,
                30, 30,
                20, 30);

            Assert.IsTrue(rectangle.GetType() == typeof(Rectangle));
            Assert.IsTrue(rectangle.Height == 10 && rectangle.Width == 10);
            Assert.IsTrue(rectangle.Lines.Count == 4);
            Assert.AreEqual(15, rectangle.CenterPoint.X);
            Assert.AreEqual(15, rectangle.CenterPoint.Y);            Assert.AreEqual(rectangle.Fill, Color.Empty);
            Assert.AreEqual(rectangle.Stroke, Color.Black);
            Assert.AreEqual(100, rectangle.ComputeArea());
            Assert.AreEqual(10, rectangle.CalculateHeight());
            Assert.AreEqual(10, rectangle.CalculateWidth());
            Assert.IsFalse(rectangle.CompositeShape);
            rectangle.Fill = Color.Aqua;
            Assert.AreEqual(Color.Aqua, rectangle.Fill);
            foreach (var line in rectangle.Lines)
            {
                Assert.IsTrue(line.ComputeLength() == 10);
            }
        }
Пример #7
0
 public void TestRectangleConstructor2()
 {
     // test that side1 and side2 are set by constructor
     Shapes.Rectangle rect = new Shapes.Rectangle(5, 3);
     Assert.AreEqual(5, rect.Side1);
     Assert.AreEqual(3, rect.Side2);
 }
Пример #8
0
        static void Main()
        {
            Triangle myTriangle = new Triangle(4, 8);
            Rectangle myRectangle = new Rectangle(4, 8);
            Circle myCircle = new Circle(6);

            List<IShape> shapes = new List<IShape>()
            {
                myCircle, myRectangle, myTriangle
            };

            shapes.ForEach(shape => Console.WriteLine(shape
                .GetType().ToString() + " - Area = " +  shape.CalculateArea()));

            shapes.ForEach(shape => Console.WriteLine(shape
                .GetType().ToString() + " - Perimeter = " + shape.CalculatePerimeter()));

            double shapesAreasTogether = 0;
            shapes.ForEach(shape => shapesAreasTogether += shape.CalculateArea());
            Console.WriteLine("\nShapes Areas Together = {0}", shapesAreasTogether);

            double shapesPerimetersTogether = 0;
            shapes.ForEach(shape => shapesPerimetersTogether += shape.CalculatePerimeter());
            Console.WriteLine("\nShapes Perimeters Together = {0}", shapesPerimetersTogether);
        }
Пример #9
0
        private static void DrawRectangle(Graphics g, Rectangle r)
        {
            if (r.Solid)
            {
                Brush brush;

                if (r.IsSelect)
                {
                    brush = CreateHatchBrush(r.FillColor);
                }
                else
                {
                    brush = new SolidBrush(r.FillColor);
                }

                g.FillRectangle(brush,
                                r.TopLeft.X, r.TopLeft.Y,
                                (float)r.Width, (float)r.Height);

                brush.Dispose();
            }

            using (var pen = new Pen(r.LineColor, r.LineWidth))
                g.DrawRectangle(pen,
                                r.TopLeft.X, r.TopLeft.Y,
                                (float)r.Width, (float)r.Height);
        }
Пример #10
0
 public void TestRectangleCalcArea()
 {
     Rectangle myRec = new Rectangle();
     myRec.height = 2;
     myRec.width = 3;
     Assert.AreEqual(myRec.Area(), 6);
 }
Пример #11
0
        public void Area_should_be_height_times_length()
        {
            var rectangle = new Rectangle {Height = 10, Length = 5};
            var area = rectangle.GetArea();

            Assert.AreEqual(50, area);
        }
Пример #12
0
        static void Main()
        {
            Random rand = new Random();
            List<Shape> shapes = new List<Shape>();

            for (int i = 0; i < 5; i++)
            {
                Triangle triangle = new Triangle((double)rand.Next(1,20),(double)rand.Next(1,20));
                shapes.Add(triangle);
            }

            for (int i = 0; i < 5; i++)
            {
                Rectangle rectangle = new Rectangle((double)rand.Next(1, 20), (double)rand.Next(1, 20));
                shapes.Add(rectangle);
            }

            for (int i = 1; i <= 5; i++)
            {
                Circle circle = new Circle(i,i);
                shapes.Add(circle);
            }

            foreach (var shape in shapes)
            {
                string type = shape.GetType().Name;
                Console.WriteLine("{0}, surface - {1}", type, shape.GetSurface());
            }
        }
Пример #13
0
        public void TestComputeArea()
        {
            ShapeFactory sf = new ShapeFactory();

            Shapes.Rectangle rectangle = sf.MakeRectangle(0, 0, 5, 6);
            Assert.AreEqual(30, rectangle.ComputeArea(), 0);
        }
Пример #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                t?.Dispose();

                double a = double.Parse(this.A.Text);
                double b = double.Parse(this.B.Text);
                double c = double.Parse(this.C.Text);

                sXc   = float.Parse(this.sX.Text);
                sYc   = float.Parse(this.sY.Text);
                sideS = float.Parse(this.side.Text);

                rect        = new Shapes.Rectangle(new Shapes.Point(sXc - sideS, sYc - sideS), new Shapes.Point(sXc + sideS, sYc - sideS), new Shapes.Point(sXc + sideS, sYc + sideS), new Shapes.Point(sXc - sideS, sYc + sideS));
                rect.Center = new Shapes.Point(sXc, sYc);
                line        = new Line((x) => (-(a / b) * x - c / b));

                kPerp = b / a;
                perp  = new Line((x) => (b / a) * (x - sXc) + sYc);


                graphics.Clear(Color.White);

                CrossPoint();

                if (kx <= sXc && ky <= sYc)
                {
                    moveKx = -1;
                    moveKy = -1;
                }
                else if (kx <= sXc && ky >= sYc)
                {
                    moveKx = -1;
                    moveKy = 1;
                }
                else if (kx >= sXc && ky <= sYc)
                {
                    moveKx = 1;
                    moveKy = -1;
                }
                else if (kx >= sXc && ky >= sYc)
                {
                    moveKx = 1;
                    moveKy = 1;
                }
                else
                {
                    throw new ArgumentException("Incorrect data!");
                }

                t = new System.Threading.Timer(new TimerCallback((object o) => { this.graphics.Clear(Color.White); DrawLine(); DrawSquare(); this.canvas.Image = bmp; }), 0, 1000, 1);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
                MessageBox.Show(exc.StackTrace);
            }
        }
Пример #15
0
        static void Main(string[] args)
        {
            Shapes.Rectangle r1 = new Shapes.Rectangle(1, 4);
            Shapes.Triangle  t1 = new Shapes.Triangle(2, 3);

            IShape r5 = new Shapes.Rectangle(2, 2);

            if (r1 is Shapes.Rectangle)
            {
                Console.WriteLine("r1 is a Retangle");
                Shapes.Rectangle r2 = (Shapes.Rectangle)r1;
                Shapes.Rectangle r3 = r1 as Shapes.Rectangle;
            }

            List <Shape> shapes = new List <Shape>();

            shapes.Add(r1);
            shapes.Add(t1);
            shapes.Add(new Shapes.Square(3));
            shapes.Add(new Shapes.Rectangle(2, 4));
            shapes.Add(new Shapes.Square(1));


            Console.WriteLine(shapes.Count);

            foreach (var item in shapes)
            {
                Console.WriteLine(item.GetType());
                Console.WriteLine(item.Area());
            }

            List <Shape> result   = shapes.Where(o => o.Area() > 4).ToList();
            var          rectList = shapes.Where(r => r is Shapes.Rectangle).ToList();

            foreach (var item in rectList)
            {
                Console.WriteLine(item.GetType());
                Console.WriteLine(item);
            }

            var trilist = (from t in shapes where t is Shapes.Triangle select t).ToList();

            Dictionary <string, Shape> dict = new Dictionary <string, Shape>();

            Console.ReadLine();



            //            Rectangle Rect1 = new Rectangle(1, 0);

            //            try
            //            {
            //                Rect1.Area();
            //            }
            //            catch (Exception e)
            //            {
            //                Console.WriteLine(e.Message);
            //            }
        }
Пример #16
0
 public Square(Rectangle rect)
     : base(rect)
 {
     if (Math.Abs(rect.Width - rect.Height) > 0.00001)
     {
         throw new ArgumentException("Square width and height must be the same");
     }
 }
Пример #17
0
 public static void Main()
 {
     Triangle triangle = new Triangle(4, 5);
     Console.WriteLine(triangle.CalculateSurface());
     var rectangle = new Rectangle(3, 5);
     Console.WriteLine(rectangle.CalculateSurface());
     var circle = new Circle(4);
     Console.WriteLine("{0:F2}", circle.CalculateSurface());
 }
Пример #18
0
 public void TestRectangleConstructor3()
 {
     // test that side1 and side2 are set by setter
     Shapes.Rectangle rect = new Shapes.Rectangle();
     rect.Side1 = 5;
     rect.Side2 = 3;
     Assert.AreEqual(5, rect.Side1);
     Assert.AreEqual(3, rect.Side2);
 }
Пример #19
0
 public void DefaultContructorCanComputeArea()
 {
     var rectangle = new Rectangle();
     rectangle.Top = 4;
     rectangle.Right = 3;
     rectangle.Bottom = 4;
     rectangle.Left = 3;
     Assert.AreEqual(rectangle.Area(), 12);
 }
Пример #20
0
 static void Main(string[] args)
 {
     Rectangle rectangle = new Rectangle(5, 6);
     rectangle.CalculateSruface();
     Triangle triangle = new Triangle(4, 3);
     triangle.CalculateSruface();
     Square square = new Square(7, 7);
     square.CalculateSruface();
 }
Пример #21
0
 public void TestRectangleConstructor3()
 {
     // test that top and left are set by setter
     Shapes.Rectangle rect = new Shapes.Rectangle();
     rect.Top  = 5;
     rect.Left = 3;
     Assert.AreEqual(5, rect.Top);
     Assert.AreEqual(3, rect.Left);
 }
Пример #22
0
        static void Main()
        {
            var triangle = new Triangle(4, 3);
            var rectangle = new Rectangle(12, 10);
            var square = new Square(10);

            Console.WriteLine("The Area of Triangle is: {0}", triangle.CalculateSurface());
            Console.WriteLine("The Area of Rectangle is: {0}", rectangle.CalculateSurface());
            Console.WriteLine("The Area of Square is: {0}", square.CalculateSurface());
        }
Пример #23
0
        public bool CheckCollision(Circle circle, Shapes.Rectangle rectangle)
        {
            int test  = circle.X - circle.radius;
            int test2 = rectangle.X + rectangle.width;

            if ((circle.X - circle.radius) <= (rectangle.X + (rectangle.width / 2)))
            {
                return(true);
            }
            return(false);
        }
Пример #24
0
        public void TestMove()
        {
            ShapeFactory sf = new ShapeFactory();

            Shapes.Rectangle rectangle = sf.MakeRectangle(1, 2, 5, 6);
            rectangle.Move(2, 3);
            Assert.AreEqual(3, rectangle.Point1.X);
            Assert.AreEqual(5, rectangle.Point1.Y);
            Assert.AreEqual(7, rectangle.Point2.X);
            Assert.AreEqual(9, rectangle.Point2.Y);
        }
Пример #25
0
        public void TestDraw()
        {
            ShapeFactory sf = new ShapeFactory();

            Shapes.Rectangle myRectangle = sf.MakeRectangle(1, 2, 5, 6);
            Bitmap           bitmap      = new Bitmap(1024, 1024, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics         g           = Graphics.FromImage(bitmap);

            myRectangle.Draw(g);
            bitmap.Save("rectangle.bmp");
        }
Пример #26
0
        public void RectangleAreaTest()
        {
            Rectangle[] rects = new Rectangle[3];
            rects[0] = new Rectangle(2, 3);
            rects[1] = new Rectangle(1.22, 3.21);
            rects[2] = new Rectangle(4.21, 2);

            Assert.AreEqual(6, rects[0].CalculateSurface());
            Assert.AreEqual(3.9162, rects[1].CalculateSurface());
            Assert.AreEqual(8.42, rects[2].CalculateSurface());
        }
Пример #27
0
        public void TestGetHeight()
        {
            ShapeFactory sf = new RectangleFactory();

            Shapes.Rectangle rectangle = (Shapes.Rectangle)sf.Create2dShape();
            rectangle.Point1.X = 2;
            rectangle.Point1.Y = 2;
            rectangle.Point2.X = 4;
            rectangle.Point2.Y = 4;
            Assert.AreEqual(2, rectangle.GetHeight());
        }
Пример #28
0
        public void TestComputeArea()
        {
            ShapeFactory sf = new RectangleFactory();

            Shapes.Rectangle rectangle = (Shapes.Rectangle)sf.Create2dShape();
            rectangle.Point1.X = 0;
            rectangle.Point1.Y = 0;
            rectangle.Point2.X = 5;
            rectangle.Point2.Y = 6;
            Assert.AreEqual(30, rectangle.ComputeArea(), 0);
        }
Пример #29
0
        static void Main()
        {
            var rect = new Rectangle(12, 32.21);
            var square = new Square(12, 12);
            var tri = new Triangle(33, 12);

            Console.WriteLine(rect.CalculateSurface());
            Console.WriteLine(square.CalculateSurface());
            Console.WriteLine(tri.CalculateSurface());

            var squareCheck = new Square(12, 13);
        }
Пример #30
0
        public void BadScaleTest()
        {
            List <Point> points = new List <Point>();

            var rectangle = new Rectangle(
                new Point(20, 20),
                new Point(30, 20),
                new Point(30, 30),
                new Point(20, 30));

            Assert.That(() => rectangle.Scale(-20), Throws.TypeOf <ShapeException>()
                        .With.Message.EqualTo("Invalid scale factor"));
        }
Пример #31
0
        static void Main()
        {
            var shapes = new Shape[3];

            shapes[0] = new Rectangle(3, 4);
            shapes[1] = new Triangle(3, 4);
            shapes[2] = new Square(3);

            foreach (var shape in shapes)
            {
                Console.WriteLine(shape.CalculateSurface());
            }
        }
Пример #32
0
        public void AddShapeTwicetest()
        {
            var c       = new CompositeShape();
            var rpoint1 = new Point(20, 20);
            var rpoint2 = new Point(30, 20);
            var rpoint3 = new Point(30, 30);
            var rpoint4 = new Point(20, 30);
            var rect    = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            c.Add(rect);
            Assert.That(() => c.Add(rect), Throws.TypeOf <ShapeException>()
                        .With.Message.EqualTo("This shape has already been added to a composite"));
        }
Пример #33
0
        public void TestValidConstruction()
        {
            ShapeFactory sf = new RectangleFactory();

            Shapes.Rectangle rectangle = (Shapes.Rectangle)sf.Create2dShape();
            rectangle.Point1.X = 1;
            rectangle.Point1.Y = 2;
            rectangle.Point2.X = 5;
            rectangle.Point2.Y = 6;
            Assert.AreEqual(1, rectangle.Point1.X);
            Assert.AreEqual(2, rectangle.Point1.Y);
            Assert.AreEqual(5, rectangle.Point2.X);
            Assert.AreEqual(6, rectangle.Point2.Y);
        }
Пример #34
0
        static void Main(string[] args)
        {
            var circle = new Circle(5);
            Console.WriteLine(circle.CalculateArea());
            Console.WriteLine(circle.CapculatePerimeter());

            var triangle = new Triangle(2, 2);
            Console.WriteLine(triangle.CalculateArea());
            Console.WriteLine(triangle.CapculatePerimeter());

            var rectangle = new Rectangle(3, 3);
            Console.WriteLine(rectangle.CalculateArea());
            Console.WriteLine(rectangle.CapculatePerimeter());
        }
Пример #35
0
        /// <summary>
        /// Represent the Main method for execution of
        /// C# console applications 
        /// </summary>
        public static void Main()
        {
            Circle circle = new Circle(5);
            Console.WriteLine(
                "I am a circle. My perimeter is {0:f2}. My surface is {1:f2}.",
                circle.CalcPerimeter(),
                circle.CalcSurface());

            Rectangle rect = new Rectangle(2, 3);
            Console.WriteLine(
                "I am a rectangle. My perimeter is {0:f2}. My surface is {1:f2}.",
                rect.CalcPerimeter(),
                rect.CalcSurface());
        }
Пример #36
0
        static void Main(string[] args)
        {
            Shapes.Rectangle r1 = new Shapes.Rectangle(1, 4);
            Shapes.Triangle  t1 = new Shapes.Triangle(2, 3);

            IShape r5 = new Shapes.Rectangle(2, 2);

            //if (r1 is Rectangle)
            //{
            //    Console.WriteLine("r1 is a Retangle");
            //    Rectangle r2 = (Rectangle)r1;
            //    Rectangle r3 = r1 as Rectangle;
            //}

            List <Shape> shapes = new List <Shape>();

            shapes.Add(r1);
            shapes.Add(t1);
            shapes.Add(new Shapes.Rectangle(2, 4));

            Console.WriteLine(shapes.Count);

            for (int i = 0; i < shapes.Count; i++)
            {
            }

            foreach (var item in shapes)
            {
                Console.WriteLine(item.GetType());
                Console.WriteLine(item.Area());
            }

            Dictionary <string, Shape> dict = new Dictionary <string, Shape>();

            Console.ReadLine();



            //            Rectangle Rect1 = new Rectangle(1, 0);

            //            try
            //            {
            //                Rect1.Area();
            //            }
            //            catch (Exception e)
            //            {
            //                Console.WriteLine(e.Message);
            //            }
        }
Пример #37
0
        static void Main(string[] args)
        {
            IShape[] shapes = new IShape[3];

            shapes[0] = new Circle(5.5);
            shapes[1] = new Triangle(20,20,10);
            shapes[2] = new Rectangle(10,10);

            foreach (var shape in shapes)
            {
                Console.WriteLine("AREA: " +shape.CalculateArea() + " : " + shape);
                Console.WriteLine("PERIMETER: " + shape.CalculatePerimeter() + " : " + shape);
                Console.WriteLine(Environment.NewLine);
            }
        }
Пример #38
0
        public void TestMove()
        {
            ShapeFactory sf = new RectangleFactory();

            Shapes.Rectangle rectangle = (Shapes.Rectangle)sf.Create2dShape();
            rectangle.Point1.X = 1;
            rectangle.Point1.Y = 2;
            rectangle.Point2.X = 5;
            rectangle.Point2.Y = 6;
            rectangle.Move(2, 3);
            Assert.AreEqual(3, rectangle.Point1.X);
            Assert.AreEqual(5, rectangle.Point1.Y);
            Assert.AreEqual(7, rectangle.Point2.X);
            Assert.AreEqual(9, rectangle.Point2.Y);
        }
Пример #39
0
        static void Main()
        {
            List<Shape> shape = new List<Shape>();
            Square square = new Square(4);
            shape.Add(square);
            Triangle triangle = new Triangle(7.8, 4.8);
            shape.Add(triangle);
            Rectangle rectangle = new Rectangle(8, 5.7);
            shape.Add(rectangle);

            foreach (var item in shape)
            {
                Console.WriteLine(item.GetType().Name + " surfase is " + item.CalculateSurface());
            }
        }
Пример #40
0
        static void Main(string[] args)
        {
            Rectangle rect = new Rectangle(4, 5);
            EquilateralTriangle triangle = new EquilateralTriangle(3, 3, 3);
            Circle circle = new Circle(4);
            List<BasicShape> figures = new List<BasicShape>();
            figures.Add(rect);
            figures.Add(triangle);
            figures.Add(circle);

            for (int i = 0; i < figures.Count; i++)
            {
                Console.WriteLine("Area: {0}",figures[i].CalculateArea());
                Console.WriteLine("Perimeter: {0}",figures[i].CalculatePerimeter());
            }
        }
Пример #41
0
        public static void Main(string[] args)
        {
            Point pt1 = new Point(1, 1);
            Rectangle rec1 = new Rectangle(2, 2, pt1);
            Circle cic1 = new Circle(2, pt1);

            List<IShape> listOfShapes = new List<IShape>();
            listOfShapes.Add(pt1);
            listOfShapes.Add(rec1);
            listOfShapes.Add(cic1);

            for (int i = 0; i < listOfShapes.Count; i++)
            {
                Console.WriteLine("The Area for index# " + i + " is " + listOfShapes[i].Area());
                Console.WriteLine("The Perimeter for index# " + i + " is " + listOfShapes[i].Perimeter());
                Console.WriteLine(" ");
            }
        }
        public static void Main()
        {
            var triangle = new Triangle(10.5, 8.5);
            var rectangle = new Rectangle(8d, 8d);
            var circle = new Circle(5d);

            var shapes = new Shape[] 
            {
                triangle, rectangle, circle
            };

            foreach (Shape shape in shapes)
            {
                var result = new StringBuilder();
                result.AppendLine(string.Format("{0}'s surface: {1}", shape.GetType().Name, shape.CalculateSurface()));
                Console.WriteLine(result.ToString());
            }
        }
Пример #43
0
        static void Main(string[] args)
        {
            Point centreRect = new Point(1, 1);
            Point centreSquare = new Point(0, 0);

            Rectangle rect = new Rectangle(3, 5, centreRect);
            Square square = new Square(2, centreSquare);
            Ellipse ellipse = new Ellipse(2, 1, centreSquare);

            Console.WriteLine(rect.ToString());
            Console.WriteLine(rect.GetArea() + " " + rect.GetPerimeter());

            Console.WriteLine(square.ToString());
            Console.WriteLine(square.GetArea() + " " + square.GetPerimeter());

            Console.WriteLine(ellipse.ToString());
            Console.WriteLine(ellipse.GetArea() + " " + ellipse.GetPerimeter());
        }
Пример #44
0
        public static void Main()
        {
            IShape triangle1 = new Triangle(2.5, 2, 60);
            IShape triangle2 = new Triangle(3.1, 2.1, 90);

            IShape rect1 = new Rectangle(2.5, 2);
            IShape rect2 = new Rectangle(3.1, 2.1);

            IShape circle1 = new Circle(2.5);
            IShape circle2 = new Circle(2.1);

            IShape[] shapes = new IShape[6] { triangle1, triangle2, rect1, rect2, circle1, circle2 };

            foreach (var shape in shapes)
            {
                Console.WriteLine("{0,-20}: Perimeter: {1:N2}, Area: {2:N2}", shape.GetType().Name, shape.CalculatePerimeter(), shape.CalculateArea());
            }
        }
Пример #45
0
        static void Main(string[] args)
        {
            IShape triangleOne = new Triangle(2.5, 2, 60);
            IShape triangleTwo = new Triangle(3.1, 2.1, 90);

            IShape rectangleOne = new Rectangle(2.5, 2);
            IShape rectangleTwo = new Rectangle(3.1, 2.1);

            IShape circleOne = new Circle(2.5);
            IShape circleTwo = new Circle(2.1);

            IShape[] shapes = new IShape[6] { triangleOne, triangleTwo, rectangleOne, rectangleTwo, circleOne, circleTwo };

            foreach (var shape in shapes)
            {
                Console.WriteLine("{0,-20}: Perimeter: {1:N2}, Area: {2:N2}",
                    shape.GetType().Name, shape.CalculatePerimeter(), shape.CalculateArea());
            }
        }
Пример #46
0
        public void CompositeShape()
        {
            var points    = new List <Point>();
            var composite = new CompositeShape();
            var rpoint1   = new Point(20, 20);
            var rpoint2   = new Point(30, 20);
            var rpoint3   = new Point(30, 30);
            var rpoint4   = new Point(20, 30);

            var rect = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            var tpoint1  = new Point(0, 0);
            var tpoint2  = new Point(3, 0);
            var tpoint3  = new Point(0, 3);
            var triangle = new Triangle(tpoint1, tpoint2, tpoint3);

            points.Add(rpoint1);
            points.Add(rpoint2);
            points.Add(rpoint3);
            points.Add(rpoint4);
            points.Add(tpoint1);
            points.Add(tpoint2);
            points.Add(tpoint3);

            var area = rect.ComputeArea() + triangle.ComputeArea();

            composite.Add(rect);
            composite.Add(triangle);

            Assert.AreEqual(area, composite.ComputeArea());
            Assert.AreEqual(Color.Empty, composite.Fill);
            Assert.AreEqual(Color.Black, composite.Stroke);
            composite.Fill = Color.Aqua;
            Assert.AreEqual(Color.Aqua, composite.Fill);



            foreach (var point in composite.Points)
            {
                Assert.Contains(point, points);
            }
        }
Пример #47
0
        static void Main(string[] args)
        {
            Rectangle r1 = new Rectangle(3, 5);
            Rectangle r2 = new Rectangle(900, 1000);

            double r1Perimeter = r1.CalcPerimter();
            double r2Perimeter = r2.CalcPerimter();

            if (r1Perimeter == r2Perimeter)
            {
                Console.WriteLine("both rectangles have the same perimeter!");
                Console.WriteLine("Both rectangles have an area of " + String.Format("{0:0.00}", r1.CalcArea()));
            }
            else if (r1Perimeter > r2Perimeter)
            {
                Console.WriteLine("Rectangle 1 has a larger perimeter");
                Console.WriteLine("Its area is " + String.Format("{0:0.00}", r1.CalcArea()));
            }
            else
            {
                Console.WriteLine("Rectangle 2 has a larger perimeter");
                Console.WriteLine(String.Format("Its area is {0}", r2.CalcArea()));
            }

            // 2. Rectangles in an array
            Rectangle r3 = new Rectangle(3, 4);
            Rectangle r4 = new Rectangle(5, 66);
            Rectangle r5 = new Rectangle(33.1, 4.456);
            Rectangle r6 = new Rectangle(13, 9.4);

            Rectangle[] rArray = new Rectangle[4];
            rArray[0] = r3;
            rArray[1] = r4;
            rArray[2] = r5;
            rArray[3] = r6;

            foreach (Rectangle r in rArray)
            {
                Console.WriteLine(String.Format("The perimeter of the rectangle is {0:0.00} metres", r.CalcPerimter()));
                Console.WriteLine(String.Format("The area of the rectangle is {0:0.00} metres squared\n", r.CalcArea()));
            }
        }
Пример #48
0
        static void Main()
        {
            var triangle1 = new Triangle(2, 5, 60);
            var triangle2 = new Triangle(6, 7, 80);

            BasicShape rectangle1 = new Rectangle(5, 11);
            BasicShape rectangle2 = new Rectangle(6.5, 9.2);

            BasicShape circle1 = new Circle(6.1);
            BasicShape circle2 = new Circle(14.5);

            BasicShape[] shapes = new[] { triangle1, triangle2, rectangle1, rectangle2, circle1, circle2 };

            foreach (var shape in shapes)
            {
                Console.WriteLine(shape.GetType().Name);
                Console.WriteLine("Area => " + shape.CalculateArea());
                Console.WriteLine("Perimeter => " + shape.CalculatePerimeter());
            }
        }
Пример #49
0
        public static void Main()
        {
            var shapes = new List<Shape>();
            var square = new Square(10);
            var rectangle = new Rectangle(5.5, 6.5);
            var triangle = new Triangle(new Point(1, 5), new Point(3, 7), new Point(8, 3));
            var ellipse = new Ellipse(3, 7);
            var circle = new Circle(5.5);
            shapes.Add(circle);
            shapes.Add(ellipse);
            shapes.Add(triangle);
            shapes.Add(rectangle);
            shapes.Add(square);

            foreach (var shape in shapes)
            {
                Console.WriteLine(shape.ToString());
                Console.WriteLine();
            }
        }
Пример #50
0
        public void MoveTest()
        {
            var rectangle = new Rectangle(
                new Point(20, 20),
                new Point(30, 20),
                new Point(30, 30),
                new Point(20, 30));

            rectangle.Move(40, 40);
            Assert.AreEqual(35, rectangle.Points[0].X);
            Assert.AreEqual(35, rectangle.Points[0].Y);

            Assert.AreEqual(45, rectangle.Points[1].X);
            Assert.AreEqual(35, rectangle.Points[1].Y);

            Assert.AreEqual(45, rectangle.Points[2].X);
            Assert.AreEqual(45, rectangle.Points[2].Y);

            Assert.AreEqual(35, rectangle.Points[3].X);
            Assert.AreEqual(45, rectangle.Points[3].Y);
        }
Пример #51
0
Файл: Main.cs Проект: sorabji/cs
        public static void Main(string[] args)
        {
            GeometricFigure[] g = new GeometricFigure[3];
            g[0] = new Rectangle(10,20).ComputeArea();
            g[1] = new Square(5).ComputeArea();
            g[2] = new Triangle(5,10).ComputeArea();

            Console.WriteLine("displaying datas...");

            DisplayData(g);

            for (int i=0; i<g.Length; i++)
            {
                g[i].Height = i*12+1;
                g[i].ComputeArea();
            }

            Console.WriteLine("changed stuff...redisplaying");

            DisplayData(g);
        }
Пример #52
0
        public void RotateTest()
        {
            var rectangle = new Rectangle(
                new Point(20, 20),
                new Point(30, 20),
                new Point(30, 30),
                new Point(20, 30));

            rectangle.Rotate(90);
            Assert.AreEqual(30, rectangle.Points[0].X);
            Assert.AreEqual(20, rectangle.Points[0].Y);

            Assert.AreEqual(30, rectangle.Points[1].X);
            Assert.AreEqual(30, rectangle.Points[1].Y);

            Assert.AreEqual(20, rectangle.Points[2].X);
            Assert.AreEqual(30, rectangle.Points[2].Y);

            Assert.AreEqual(20, rectangle.Points[3].X);
            Assert.AreEqual(20, rectangle.Points[3].Y);
        }
Пример #53
0
        public void ScaleTest()
        {
            var c       = new CompositeShape();
            var rpoint1 = new Point(1, 1);
            var rpoint2 = new Point(2, 1);
            var rpoint3 = new Point(2, 2);
            var rpoint4 = new Point(1, 2);
            var rect    = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            c.Add(rect);
            var tpoint1  = new Point(0, 0);
            var tpoint2  = new Point(1, 0);
            var tpoint3  = new Point(0, 1);
            var triangle = new Triangle(tpoint1, tpoint2, tpoint3);

            c.Add(triangle);
            var area = c.ComputeArea() * 2;

            c.Scale(2);
            Assert.Less(Math.Abs(c.ComputeArea() - area), .000000000000001);
        }
Пример #54
0
        public void RemoveAllShapes()
        {
            var c       = new CompositeShape();
            var rpoint1 = new Point(20, 20);
            var rpoint2 = new Point(30, 20);
            var rpoint3 = new Point(30, 30);
            var rpoint4 = new Point(20, 30);
            var rect    = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            c.Add(rect);
            var tpoint1  = new Point(0, 0);
            var tpoint2  = new Point(3, 0);
            var tpoint3  = new Point(0, 3);
            var triangle = new Triangle(tpoint1, tpoint2, tpoint3);

            c.Add(triangle);

            c.RemoveAllShapes();
            Assert.AreEqual(0, c.Points.Count);
            Assert.AreEqual(0, c.thisShapesList.Count);
        }
Пример #55
0
        public void ScaleTest()
        {
            List <Point> points = new List <Point>();

            var rectangle = new Rectangle(
                new Point(20, 20),
                new Point(30, 20),
                new Point(30, 30),
                new Point(20, 30));

            points.Add(new Point(20, 20));
            points.Add(new Point(30, 20));
            points.Add(new Point(30, 30));
            points.Add(new Point(20, 30));
            rectangle.Scale(10);
            for (int i = 0; i < rectangle.Points.Count; i++)
            {
                points[i].X *= 10;
                points[i].Y *= 10;
                Assert.AreEqual(points[i].X, rectangle.Points[i].X);
                Assert.AreEqual(points[i].Y, rectangle.Points[i].Y);
            }
        }
Пример #56
0
        public void RemoveShapeTest()
        {
            var points    = new List <Point>();
            var composite = new CompositeShape();
            var rpoint1   = new Point(20, 20);
            var rpoint2   = new Point(30, 20);
            var rpoint3   = new Point(30, 30);
            var rpoint4   = new Point(20, 30);

            var rect = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            var tpoint1  = new Point(0, 0);
            var tpoint2  = new Point(3, 0);
            var tpoint3  = new Point(0, 3);
            var triangle = new Triangle(tpoint1, tpoint2, tpoint3);

            points.Add(rpoint1);
            points.Add(rpoint2);
            points.Add(rpoint3);
            points.Add(rpoint4);


            var area = rect.ComputeArea() + triangle.ComputeArea();

            composite.Add(rect);
            composite.Add(triangle);

            Assert.AreEqual(area, composite.ComputeArea());

            composite.RemoveShape(triangle);

            foreach (var point in composite.Points)
            {
                Assert.Contains(point, points);
            }
            Assert.AreEqual(rect.ComputeArea(), composite.ComputeArea());
        }
Пример #57
0
 public void TestRectangleComputePerimeter()
 {
     Shapes.Rectangle myRectangle = new Shapes.Rectangle(5, 10);
     Assert.AreEqual(30, myRectangle.Perimeter());
 }
Пример #58
0
 public void TestRectangleDefaultColors()
 {
     Shapes.Rectangle rect = new Shapes.Rectangle();
     Assert.AreEqual(Colors.AliceBlue, rect.BorderColor);
     Assert.AreEqual(Colors.Bisque, rect.FillColor);
 }
Пример #59
0
 public void TestRectanglePerimeterIsZero()
 {
     Shapes.Rectangle rect = new Shapes.Rectangle();
     rect.Perimeter();
 }
Пример #60
0
 public void TestRectangleAreaIsZero()
 {
     Shapes.Rectangle rect = new Shapes.Rectangle();
     rect.Area();
 }