Beispiel #1
0
        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());

            //Test the circle encapsulation
            try
            {
                Circle circle2 = new Circle(-3);
                Console.WriteLine("I am a circle. " +
                    "My perimeter is {0:f2}. My surface is {1:f2}.",
                    circle2.CalcPerimeter(), circle2.CalcSurface());

            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
            //Test the rectangle encapsulation
            try
            {
                Rectangle rect3 = new Rectangle(2, 0);
            Console.WriteLine("I am a rectangle. " +
                "My perimeter is {0:f2}. My surface is {1:f2}.",
                rect.CalcPerimeter(), rect.CalcSurface());
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }

            try
            {
                Rectangle rect2 = new Rectangle(-2, 3);
                Console.WriteLine("I am a rectangle. " +
                    "My perimeter is {0:f2}. My surface is {1:f2}.",
                    rect.CalcPerimeter(), rect.CalcSurface());

            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        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());

            // re-factored
            List <Figure> figures = new List <Figure>()
            {
                new Circle(5), new Rectangle(2, 3)
            };

            foreach (var figure in figures)
            {
                figure.Introduce();
                Console.WriteLine("My perimeter is {0:f2}. My surface is {1:f2}.",
                                  figure.CalcPerimeter(), figure.CalcSurface());
            }
        }
Beispiel #3
0
        public static void Main()
        {
            try
            {
                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 rectangle = new Rectangle(-2, 3);

                Console.WriteLine(
                    "I am a Rectangle. " + "My perimeter is {0:f2}. My surface is {1:f2}.",
                    rectangle.CalcPerimeter(),
                    rectangle.CalcSurface());
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.WriteLine("GoobBye");
            }
        }
 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());
 }
Beispiel #5
0
        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());
        }
        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());

            Console.WriteLine("rect width {0}", rect.Width);
            Console.WriteLine("rect height {0}",rect.Height);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Circle circle = new Circle(5);

            Console.WriteLine("I am a circle. " +
                              $"My perimeter is {circle.CalcPerimeter():f2}." +
                              $"My surface is {circle.CalcSurface():f2}.");

            Rectangle rect = new Rectangle(2, 3);

            Console.WriteLine("I am a rectangle. " +
                              $"My perimeter is {rect.CalcPerimeter():f2}." +
                              $"My surface is {rect.CalcSurface():f2}.");
        }
Beispiel #8
0
        internal static void Main()
        {
            var circle = new Circle(5);

            Console.WriteLine("I am a circle. " +
                              "My perimeter is {0:f2}. My surface is {1:f2}.",
                              circle.CalcPerimeter(), circle.CalcSurface());

            var 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());
        }
        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());

            Console.WriteLine("rect width {0}", rect.Width);
            Console.WriteLine("rect height {0}", rect.Height);
        }
Beispiel #10
0
 public static void Main()
 {
     const string MessgaeFormat = "I am a {0} and my perimeter is {1:f2}. My surface is {2:f2}.";
     Figure circle = new Circle(5);
     Console.WriteLine(
         MessgaeFormat,
         circle.GetType().Name,
         circle.CalcPerimeter(),
         circle.CalcSurface());
     Figure rect = new Rectangle(2, 3);
     Console.WriteLine(
         MessgaeFormat,
         rect.GetType().Name,
         rect.CalcPerimeter(),
         rect.CalcSurface());
 }
Beispiel #11
0
        private static void Main()
        {
            IFigure circle = new Circle(5);

            Console.WriteLine(
                "I am a circle. " + "My perimeter is {0:f2}. My surface is {1:f2}.",
                circle.CalcPerimeter(),
                circle.CalcSurface());

            IFigure 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());
        }
        public static void Main()
        {
            Circle circle = new Circle(5);

            Console.WriteLine("Circle");
            Console.WriteLine("Perimeter: {0}", circle.CalcPerimeter());
            Console.WriteLine("Surface: {0}", circle.CalcSurface());
            Console.WriteLine();

            Rectangle rect = new Rectangle(3, 4);

            Console.WriteLine("Rectangle");
            Console.WriteLine("Perimeter: {0}", rect.CalcPerimeter());
            Console.WriteLine("Surface: {0}", rect.CalcSurface());
            Console.WriteLine();
        }
Beispiel #13
0
 static void Main()
 {
     try
     {
         Figure circle = new Circle(5);
         Console.WriteLine("I am a circle. " +
                           "My perimeter is {0:f2}. My surface is {1:f2}.",
                           circle.CalcPerimeter(), circle.CalcSurface());
         Figure 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());
     }
     catch (ArgumentOutOfRangeException e)
     {
         Console.WriteLine(e.Message);
     }
 }
Beispiel #14
0
        public static void Main()
        {
            const string MessgaeFormat = "I am a {0} and my perimeter is {1:f2}. My surface is {2:f2}.";
            Figure       circle        = new Circle(5);

            Console.WriteLine(
                MessgaeFormat,
                circle.GetType().Name,
                circle.CalcPerimeter(),
                circle.CalcSurface());
            Figure rect = new Rectangle(2, 3);

            Console.WriteLine(
                MessgaeFormat,
                rect.GetType().Name,
                rect.CalcPerimeter(),
                rect.CalcSurface());
        }
Beispiel #15
0
 static void Main()
 {
     try
     {
         Figure circle = new Circle(5);
         Console.WriteLine("I am a circle. " +
             "My perimeter is {0:f2}. My surface is {1:f2}.",
             circle.CalcPerimeter(), circle.CalcSurface());
         Figure 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());
     }
     catch (ArgumentOutOfRangeException e)
     {
         Console.WriteLine(e.Message);                
     }
     
 }
Beispiel #16
0
        public static void Main()
        {
            Figure circle          = new Circle(5);
            double circlePerimeter = circle.CalcPerimeter();
            double circleSurface   = circle.CalcSurface();

            Console.WriteLine(
                "I am a circle. My perimeter is {0:f2}. My surface is {1:f2}.",
                circlePerimeter,
                circleSurface);

            Figure rect          = new Rectangle(2, 3);
            double rectPerimeter = rect.CalcPerimeter();
            double rectSurface   = rect.CalcSurface();

            Console.WriteLine(
                "I am a rectangle. My perimeter is {0:f2}. My surface is {1:f2}.",
                rectPerimeter,
                rectSurface);
        }
Beispiel #17
0
        public static void Main()
        {
            // Circle tests
            double  radius = 5;
            ICircle circle = new Circle(radius);

            Console.WriteLine(
                "I am a circle. " +
                "My perimeter is {0:f2}. My surface is {1:f2}.",
                circle.CalcPerimeter(),
                circle.CalcSurface());

            // Rectangle tests
            double     width  = 2;
            double     height = 3;
            IRectangle rect   = new Rectangle(width, height);

            Console.WriteLine(
                "I am a rectangle. " +
                "My perimeter is {0:f2}. My surface is {1:f2}.",
                rect.CalcPerimeter(),
                rect.CalcSurface());
        }
Beispiel #18
0
        static void Main()
        {
            // Промених типа на circle и rect, за да се види, че полиморфизма си работи
            Figure circle = new Circle(5);

            Console.WriteLine("I am a circle. " + "My perimeter is {0:f2}. My surface is {1:f2}.", circle.CalcPerimeter(), circle.CalcSurface());
            Figure 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());
        }
Beispiel #19
0
        static void Main()
        {
            var circle = new Circle(5);

            Console.WriteLine("I am a circle. " +
                              $"My perimeter is {circle.CalcPerimeter():f2}. My surface is {circle.CalcSurface():f2}.");

            var rect = new Rectangle(2, 3);

            Console.WriteLine("I am a rectangle. " +
                              $"My perimeter is {rect.CalcPerimeter():f2}. My surface is {rect.CalcSurface():f2}.");
        }