Inheritance: Shape
Exemple #1
0
 public void SquareTest(int radius)
 {
     var circle = new Circle(radius);
     Assert.AreEqual(Math.Round(Math.PI, 2) * Math.Pow(radius, 2) / 2, circle.Square);
     //Assert.DoesNotThrow(() => new Circle(radius));
     //Assert.That(ex.Message, Is.EqualTo("Радиус не может быть равен нулю!"));
 }
        public void Area_should_be_pi_times_radius_squared()
        {
            var circle = new Circle {Radius = 10};
            var area = circle.GetArea();

            Assert.AreEqual(314.2, area.Decimals(1));
        }
        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);
        }
        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());
            }
        }
 /// <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);
 }
Exemple #6
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());
 }
 public virtual bool Equals(Circle circle)
 {
     if (circle == null || GetType() != circle.GetType())
         return false;
     else if (Type == circle.Type && _radius == circle._radius)
         return true;
     else
         return false;
 }
        public void CircleAreaTest()
        {
            Circle[] circles = new Circle[3];
            circles[0] = new Circle(4);
            circles[1] = new Circle(6);
            circles[2] = new Circle(1.23);

            Assert.AreEqual(4*4*Math.PI, circles[0].CalculateSurface());
            Assert.AreEqual(6*6*Math.PI, circles[1].CalculateSurface());
            Assert.AreEqual(1.23*1.23*Math.PI, circles[2].CalculateSurface());
        }
Exemple #9
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());
        }
Exemple #10
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());
        }
Exemple #11
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);
            }
        }
Exemple #12
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());
            }
        }
Exemple #13
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(" ");
            }
        }
Exemple #14
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());
            }
        }
        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());
            }
        }
Exemple #16
0
        static void Main()
        {
            var circle = new Circle(10.5);
            var rectangle = new Rectanlge(4.5, 5.4);
            var triangle = new Triangle(5, 6, 4, 5);

            var shapes = new List<IShape>()
            {
                circle,
                rectangle,
                triangle
            };

            foreach (var shape in shapes)
            {
                Console.WriteLine("{0} -> Area: {1:F4}; Perimeter: {2:F4};",
                    shape.GetType().Name, shape.CalculateArea(), shape.CalculatePerimeter());
            }
        }
Exemple #17
0
        static void Main(string[] args)
        {
            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            // Calls base class implementation
            cir.Draw();

            // Make an array of Shape-compatible objects
            Shape[] myShapes = {new Hexagon(), new Circle(), new Hexagon("Mick")
                              , new Circle("Beth"), new Hexagon("Linda")};
            // Loop over each item and interact with the polymorphic interface
            foreach (Shape s in myShapes) {
                s.Draw();
            }

            Console.ReadLine();
        }
        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());
            }
        }
Exemple #19
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());
            }
        }
Exemple #20
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();
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Polymorphism *****\n");

            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            // Calls base class implementation!
            cir.Draw();
            Console.WriteLine();

            // Make an array of Shap-compatible objects.
            Shape[] myShapes = {new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda")};

            // Loop over each item and interact with
            // Polymorphic interface.
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }

            Console.WriteLine();

            // This calls the Draw() method of the ThreeDCircle.
            ThreeDCircle o = new ThreeDCircle();
            o.Draw();

            DrawCircle(o);
            Console.WriteLine();

            // This calls the Draw() method of the parent!
            ((Circle)o).Draw();

            Circle oCopy = o as Circle;
            oCopy.Draw();
            Console.WriteLine();

            Console.ReadKey();
        }
Exemple #22
0
        static void Main(string[] args)
        {
            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            cir.Draw();

            Shape[] myShapes = { new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda") };

            foreach (Shape s in myShapes)
            {
                s.Draw();
            }

            ThreeDCircle o = new ThreeDCircle();
            o.Draw();

            ((Circle)o).Draw();

            Console.ReadLine();
        }
        public static void Main()
        {
            IShape[] shapes;

            IShape testTriangle1 = new Triangle(1.2, 2, 30);
            IShape testTriangle2 = new Triangle(3, 1.3, 60);

            IShape testRectangle1 = new Rectangle(2, 3);
            IShape testRectangle2 = new Rectangle(2, 3);

            IShape testCircle1 = new Circle(1.2);
            IShape testCircle2 = new Circle(3);

            shapes = new IShape[6] { testTriangle1, testTriangle2, testRectangle1, testRectangle2, testCircle1, testCircle2 };
            int shapesLength = shapes.Length;

            for (int i = 0; i < shapesLength; i++)
            {
                IShape shape = shapes[i];
                Console.WriteLine("Shape [{0}] has Area: ({1:0.00}) and Perimeter: ({2:0.00})", shape.GetType().Name, shape.CalculateArea(), shape.CalculatePerimeter());
            }
        }
Exemple #24
0
        static void Main(string[] args)
        {
            Square x = new Square(5);
            Circle c = new Circle(3.5);
            Triangle t = new Triangle(3, 4, 5);
            Rectangle r = new Rectangle(5, 2.5);

            //make list
            List<IShape> shapes = new List<IShape>();
            shapes.Add(x);
            shapes.Add(c);
            shapes.Add(t);
            shapes.Add(r);

            //print out
            foreach (IShape shape in shapes) {

                Console.WriteLine(shape);

            }
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            #region Circles
            // create new Circle
            Circle c1 = new Circle();
            Circle c2 = new Circle();
            Circle c3 = new Circle();

            // ToString tests
            Console.WriteLine("Circle1:\n" + c1.ToString());
            Console.WriteLine("Circle2:\n" + c2.ToString());
            Console.WriteLine("Circle3:\n" + c3.ToString());

            // Equals tests
            Console.WriteLine("Does Circle1 equal Circle2? {0}", c1.Equals(c2));
            Console.WriteLine("Does Circle1 equal Circle3? {0}", c1.Equals(c3));
            Console.WriteLine("Does Circle2 equal Circle3? {0}", c2.Equals(c3) + "\n");
            #endregion

            #region Squares
            // create new Squares
            Square s1 = new Square();
            Square s2 = new Square();
            Square s3 = new Square();

            // ToString tests
            Console.WriteLine("Square1:\n" + s1.ToString());
            Console.WriteLine("Square2:\n" + s2.ToString());
            Console.WriteLine("Square3:\n" + s3.ToString());

            // Equals tests
            Console.WriteLine("Does Square1 equal Square2? {0}", s1.Equals(s2));
            Console.WriteLine("Does Square1 equal Square3? {0}", s1.Equals(s3));
            Console.WriteLine("Does Square2 equal Square3? {0}", s2.Equals(s3) + "\n");
            #endregion

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            cir.Draw();
            Console.WriteLine();

            Shape[] myShapes = { new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda") };
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }

            Console.WriteLine();
            ThreDCircle c = new ThreDCircle();
            c.Draw();                                 //calls method form 3d circle

            Circle c1 = new ThreDCircle();
            c1.Draw();                                //calls method form  circle
            Console.ReadLine();
        }
        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}.\n",
                rect.CalcPerimeter(), rect.CalcSurface());

            Console.WriteLine(circle);
            Console.WriteLine(rect + "\n");

            try
            {
                //var circleNegativeRadius = new Circle(-5);
                //var rectangleNegativeWidth = new Rectangle(-5, 5);
                var rectangleNegativeHeight = new Rectangle(5, -5);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #28
0
        public void ShouldConvertToEnum()
        {
            var s = new Circle
            {
                Color = Colors.Red,
            };

            _engine.SetValue("s", s);

            RunTest(@"
                assert(s.Color === 0);
                s.Color = 10;
                assert(s.Color === 10);
            ");

            _engine.SetValue("s", s);

            RunTest(@"
                s.Color = 11;
                assert(s.Color === 11);
            ");

            Assert.Equal(Colors.Blue | Colors.Green, s.Color);
        }
Exemple #29
0
        public void ShouldSetEnumProperty()
        {
            var s = new Circle
            {
                Color = Colors.Red,
            };

            _engine.SetValue("s", s);

            RunTest(@"
                var domain = importNamespace('Jint.Tests.Runtime.Domain');
                var colors = domain.Colors;
                
                s.Color = colors.Blue;
                assert(s.Color === colors.Blue);
            ");

            _engine.SetValue("s", s);

            RunTest(@"
                s.Color = colors.Blue | colors.Green;
                assert(s.Color === colors.Blue | colors.Green);
            ");

            Assert.Equal(Colors.Blue | Colors.Green, s.Color);
        }
Exemple #30
0
        static void Main(string[] args)
        {
            int opt = -1;



            while (opt != 0)
            {
                Console.WriteLine("Program Bentuk-Bentuk : ");
                Console.WriteLine("============================================================");
                Console.WriteLine("1. Persegi Sama Sisi");
                Console.WriteLine("2. Ubin (Turuan Dari Persegi Sama Sisi)");
                Console.WriteLine("3. Eternit / Plafon (Turuan Dari Persegi Sama Sisi)");
                Console.WriteLine("4. Kubus (Turuan Dari Persegi Sama Sisi 3D)");
                Console.WriteLine("............................................................");
                Console.WriteLine("5. Persegi Panjang");
                Console.WriteLine("6. Papan Tulis (Turuan Dari Persegi Panjang)");
                Console.WriteLine("7. Pintu (Turuan Dari Persegi Panjang)");
                Console.WriteLine("8. Balok (Turuan Dari Persegi Panjang 3D)");
                Console.WriteLine("............................................................");
                Console.WriteLine("9. Lingkaran");
                Console.WriteLine("10. Bola");
                Console.WriteLine("11. Kerucut");
                Console.WriteLine("............................................................");
                Console.WriteLine("0. Keluar");
                Console.WriteLine("------------------------------------------------------------");

                Console.Write("Pilih Opsi : ");
                opt = Convert.ToInt32(Console.ReadLine());

                switch (opt)
                {
                case 1:
                    Square sqr1 = new Square();
                    sqr1.input().display();
                    break;

                case 2:
                    Tile tle1 = new Tile();
                    tle1.input().display();
                    break;

                case 3:
                    Plasterboard plb = new Plasterboard();
                    plb.input().display();
                    break;

                case 4:
                    Cube cube = new Cube();
                    cube.input().display();
                    break;

                case 5:
                    Rectangle rct1 = new Rectangle();
                    rct1.input().display();
                    break;


                case 6:
                    WhiteBoard whtb = new WhiteBoard();
                    whtb.input().display();
                    break;

                case 7:
                    Door door = new Door();
                    door.input().display();
                    break;

                case 8:
                    Block block = new Block();
                    block.input().display();
                    break;

                case 9:
                    Circle circle = new Circle();
                    circle.input().display();
                    break;

                case 10:
                    Sphere sphere = new Sphere();
                    sphere.input().display();
                    break;

                case 11:
                    Cone cone = new Cone();
                    cone.input().display();
                    break;

                default:
                    break;
                }

                Console.WriteLine("\n\n");
            }
        }
 public static void DrawCircle(Circle shape)
 {
     Console.WriteLine("Using DrawCircle()");
     shape.Draw();
 }