Circle class derived from Figure
Inheritance: Figure
 public static void Main()
 {
     IFigure circle = new Circle(5);
     Console.WriteLine(circle);
     IFigure rectangle = new Rectangle(2, 3);
     Console.WriteLine(rectangle);
 }
 static void Main()
 {
     Circle circle = new Circle(5);
     Console.WriteLine(circle);
     Rectangle rect = new Rectangle(2, 3);
     Console.WriteLine(rect);
 }
 public static void Main()
 {
     Circle circle = new Circle(5);
     Console.WriteLine(circle.ToString());
     Rectangle rectangle = new Rectangle(2, 3);
     Console.WriteLine(rectangle.ToString());
 }
        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.CalculatePerimeter(),
                circle.CalculateSurface());

            Rectangle rect = new Rectangle(2, 3);

            Console.WriteLine(
                "I am a rectangle. " +
                "My perimeter is {0:f2}. My surface is {1:f2}.",
                rect.CalculatePerimeter(),
                rect.CalculateSurface());

            // Throws exceptions
            IFigure[] figures =
                {
                    circle,
                    rect,
                    new Circle(-20),
                    new Rectangle(-10, 5)
                };
        }
示例#5
0
        /// <summary>
        /// Точка входа
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Массив ссылок
            Figure[] Fig = new Figure[6];

            //заполнение массива ссылками на объекты поизводных классов
            Fig[0] = new Circle(7);
            Fig[1] = new Circle(2, 3, 2);
            Fig[2] = new Rectangle();
            Fig[3] = new Rectangle(2, 3, 10, 11);
            Fig[4] = new Triangle();
            Fig[5] = new Triangle(1, 1, -2, 4, -2, -2);
            //Пока не весь массив заполнен ссылками, ловим исключение пустой ссылки 
            try
            {

                //Для каждого объекта 
                foreach (Figure item in Fig)
                {
                    //вызываем метод Show
                    item.Show();
                }
            }

            //ловим исключение
            catch (Exception e)
            {
                //выводим текст исключения
                Console.WriteLine(e.Message);
            }

            //Задерживаем консоль при отладке 
            Console.ReadKey();
        }
 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());
 }
示例#7
0
 private static void Main()
 {
     Figure circle = new Circle(5);
     Console.WriteLine(circle);
     Figure rect = new Rectangle(2, 3);
     Console.WriteLine(rect);
 }
        public static void Main()
        {
            Circle circle = new Circle(5);
            Console.WriteLine(circle + Environment.NewLine);

            Rectangle rectangle = new Rectangle(2, 3);
            Console.WriteLine(rectangle);
        }
        private static void Main()
        {
            Circle circle = new Circle(5);
            Rectangle rectengle = new Rectangle(2, 3);

            circle.Introduce();
            rectengle.Introduce();
        }
示例#10
0
        private static void Main()
        {
            Circle circle = new Circle(5);
            Console.WriteLine("I am a circle. " + circle.ToString());

            Rectangle rect = new Rectangle(2, 3);
            Console.WriteLine("I am a rectangle. " + rect.ToString());
        }
        public static void Main()
        {
            IFigure circle = new Circle(5.0);
            Console.WriteLine(circle + Environment.NewLine);

            IFigure rectangle = new Rectangle(10.2, 5.2);
            Console.WriteLine(rectangle);
        }
        public static void Main()
        {
            Circle circle = new Circle(5);
            PrintFigure(circle);

            Rectangle rect = new Rectangle(2, 3);
            PrintFigure(rect);
        }
        static void Main()
        {
            IFigure circle = new Circle(5.3);
            Console.WriteLine(circle);
            Console.WriteLine();

            IFigure rectangle = new Rectangle(6.2, 5.5);
            Console.WriteLine(rectangle);
        }
        public static void Main()
        {
            double radius = 5;
            Circle circle = new Circle(radius);
            Console.WriteLine(circle.ToString());

            double width = 2;
            double height = 3;
            Rectangle rectangle = new Rectangle(width, height);
            Console.WriteLine(rectangle.ToString());
        }
 public static void Main(string[] args)
 {
     IFigure circle = new Circle(5);
     Console.WriteLine("I am a circle. " +
         "My perimeter is {0:f2}. My surface is {1:f2}.",
         circle.CalculatePerimeter(), circle.CalculateSurface());
     IFigure rect = new Rectangle(2, 3);
     Console.WriteLine("I am a rectangle. " +
         "My perimeter is {0:f2}. My surface is {1:f2}.",
         rect.CalculatePerimeter(), rect.CalculateSurface());
 }
示例#16
0
        public static void Main()
        {
            Circle circle = new Circle(5);
            Console.WriteLine("I am a circle with radius {2}. " + "\nMy perimeter is {0:f2}. My surface is {1:f2}.", circle.CalculatePerimeter(), circle.CalculateSurface(), circle.Radius);

            Console.WriteLine(new string('-', 40));

            Rectangle rect = new Rectangle(2, 3);
            Console.WriteLine("I am a rectangle with width {2} and height {3}. " + "\nMy perimeter is {0:f2}. My surface is {1:f2}.", rect.CalculatePerimeter(), rect.CalculateSurface(), rect.Width, rect.Height);

            Console.WriteLine(new string('-', 40));
        }
示例#17
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());

            Console.WriteLine("rect width {0}", rect.Width);
            Console.WriteLine("rect height {0}",rect.Height);
        }
 private 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.CalculatePerimeter(), 
         circle.CalculateSurface());
     var rect = new Rectangle(2, 3);
     Console.WriteLine(
         "I am a rectangle. " + "My perimeter is {0:f2}. My surface is {1:f2}.", 
         rect.CalculatePerimeter(), 
         rect.CalculateSurface());
 }
示例#19
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);
            }
        }
        public static void Main()
        {
            Circle circle = new Circle(5);
            var circlePerimeter = circle.CalculatePerimeter();
            var circleArea = circle.CalculateArea();

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

            Rectangle rectangle = new Rectangle(2, 3);
            var rectanglePerimeter = rectangle.CalculatePerimeter();
            var rectangleArea = rectangle.CalculateArea();

            Console.WriteLine("I am a rectangle. " + "My perimeter is {0:f2}. My area is {1:f2}.", rectanglePerimeter, rectangleArea);
        }
        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();
        }
示例#22
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());
 }
示例#23
0
        public static void Main()
        {
            var circle = new Circle(5);

            double circlePerimeter = circle.CalculatePerimeter();
            double circleSurface = circle.CalculateSurface();

            Console.WriteLine(PrintMessageCircle, circlePerimeter, circleSurface);

            var rectangle = new Rectangle(2, 3);

            double rectanglePerimeter = rectangle.CalculatePerimeter();
            double rectangleSurface = rectangle.CalculateSurface();

            Console.WriteLine(PrintMessageRectangle, rectanglePerimeter, rectangleSurface);
        }
示例#24
0
        public static void Main()
        {
            Circle circle = new Circle(5);
            var circlePerimeter = circle.CalculatePerimeter();
            var circleSurface = circle.CalculateSurface();

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

            Rectangle rectangle = new Rectangle(2, 3);
            var rectanglePerimeter = rectangle.CalculatePerimeter();
            var rectangleSurface = rectangle.CalculateSurface();

            var rectangleInformationAsString = string.Format("I am a rectangle. My perimeter is {0:f2}. My surface is {1:f2}.",
                rectanglePerimeter, rectangleSurface);
            Console.WriteLine(rectangleInformationAsString);
        }
示例#25
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);                
     }
     
 }
示例#26
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.Perimeter(), circle.Area());
            Rectangle rect = new Rectangle(2, 3);
            //Console.WriteLine("I am a rectangle. " + "My perimeter is {0:f2}. My surface is {1:f2}.", rect.Perimeter(), rect.Area());

            Console.WriteLine(circle.ToString());
            Console.WriteLine(rect.ToString());

            //not required for the homework
            List<IFigure> figures = new List<IFigure>();
            figures.Add(circle);
            figures.Add(rect);

            foreach (var figure in figures)
            {
                Console.WriteLine(figure.Area());
            }
        }
示例#27
0
        public static void Main()
        {
            try
            {
                IFigure circle = new Circle(5);
                Console.WriteLine(
                    "I am a circle. My perimeter is {0:f2}. My surface is {1:f2}.",
                    circle.CalculationPerimeter(),
                    circle.CalculationSurface());

                IFigure rect = new Rectangle(2, 3);
                Console.WriteLine(
                    "I am a rectangle. My perimeter is {0:f2}. My surface is {1:f2}.",
                    rect.CalculationPerimeter(),
                    rect.CalculationSurface());
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Main()
        {
            Circle firstCircle = new Circle();
            firstCircle.Radius = 2.215;
            Console.WriteLine("I am a circle with radius {0}! My perimeter is {1:f2}. My surface is {2:f2}.",
                firstCircle.Radius, firstCircle.GetPerimeter(), firstCircle.GetSurface());

            Circle secondCircle = new Circle(5);
            Console.WriteLine("I am a circle with radius {0}! My perimeter is {1:f2}. My surface is {2:f2}.",
                secondCircle.Radius, secondCircle.GetPerimeter(), secondCircle.GetSurface());

            Rectangle firstRectangle = new Rectangle();
            firstRectangle.Width = 5.1;
            firstRectangle.Height = 9;
            Console.WriteLine("I am a rectangle with width {0} and height {1}! My perimeter is {2:f2}. My surface is {3:f2}.",
                firstRectangle.Width, firstRectangle.Height, firstRectangle.GetPerimeter(), firstRectangle.GetSurface());

            Rectangle secondRectangle = new Rectangle(2, 3);
            Console.WriteLine("I am a rectangle with width {0} and height {1}! My perimeter is {2:f2}. My surface is {3:f2}.",
                secondRectangle.Width, secondRectangle.Height, secondRectangle.GetPerimeter(), secondRectangle.GetSurface());
        }