static void Main(string[] args)
        {
            Console.WriteLine("This program creates shapes via abstract classes, and tests them.");
            Console.ReadKey();
            Console.WriteLine("");
            Console.WriteLine("Creating and printing a triangle:");
            Triangle triangle = new Triangle(3, 6, 8);

            Console.WriteLine(triangle.ToString());
            Console.WriteLine("");
            Console.WriteLine("Creating and printing a rectangle:");
            Rectangle rectangle = new Rectangle(5, 2);

            Console.WriteLine(rectangle.ToString());
            Console.WriteLine("");
            Console.WriteLine("Creating and printing a circle:");
            Circle circle = new Circle(4);

            Console.WriteLine(circle.ToString());
            Console.WriteLine("");
            Console.WriteLine("Creating and printing a square:");
            Square square = new Square(5);

            Console.WriteLine(square.ToString());
            Console.ReadKey();
        }
示例#2
0
 static void Main(string[] args)
 {
     //Toy a = new Toy(color: "blue", size: 15);
     //Toy b = new Toy(12, "pink");
     //Toy c = new Toy(58, "green");
     //List<Toy> toys = new List<Toy> { a, b, c };
     //Person c1 = new Children(false);
     //Children c2 = new Children(false, toys);
     //Adults ad = new Adults(true);
     //List<Children> list = new List<Children>() { (Children)c1, c2 };
     //Adults ad2 = new Adults(true, list);
     //Console.WriteLine(ad2.ToString());
     //Console.WriteLine(c1.ToString());
     //Console.WriteLine(c2.ToString());
     // Console.WriteLine(a.ToString());
     Point a = new Point(2, 2);
     Rectangle b = new Rectangle(3,2,a);
     Square d = new Square(2,a);
     Rectangle c = new Square(3,a);
     Ellipse e = new Ellipse(3, 2, a);
     Circle f = new Circle(3, a);
     Triangle t = new Triangle(3, 4, 5);
     Console.WriteLine(t.ToString());
     Console.WriteLine(t.GetArea());
     Console.WriteLine(t.GetPerimeter());
     IMovable x = new Square(2,a);
     Console.WriteLine(x.ToString());
     x.Move(3, 3);
     Console.WriteLine(x.ToString());
 }
示例#3
0
        static void Main(string[] args)
        {
            IShape[] shapes = { new Square(2),  new Triangle(1, 1,  2,  2,  3, 1), new Rectangle(2, 3), new Circle(3),
                                new Square(15), new Triangle(3, 3, 10, 10, 12, 2), new Rectangle(5, 7), new Circle(7),
                                new Square(7),  new Triangle(0, 0,  7, 15, 14, 0), new Rectangle(6, 2), new Circle(4) };
            Console.WriteLine("Все фигуры:\nТип\t\tШирина\tВысота\tПлощадь\tПериметр\tHashCode");
            foreach (IShape shape in shapes)
            {
                Console.WriteLine("{0}\t\t{1}", shape, shape.GetHashCode());
            }

            GetShapeWithMaxArea(shapes);
            GetShapeWithSecondPerimeter(shapes);

            Square    square    = new Square(2);
            Circle    circle    = new Circle(7);
            Rectangle rectangle = new Rectangle(6, 2);
            Triangle  triangle  = new Triangle(0, 0, 7, 15, 14, 0);

            Console.WriteLine("\nПоиск фигур:");
            Console.WriteLine("Тип\t\tШирина\tВысота\tПлощадь\tПериметр");
            Console.WriteLine(square.ToString());
            Console.WriteLine(circle.ToString());
            Console.WriteLine(rectangle.ToString());
            Console.WriteLine(triangle.ToString());
            Console.WriteLine("\nТип\t\tШирина\tВысота\tПлощадь\tПериметр");
            foreach (IShape shape in shapes)
            {
                if (square.Equals(shape) || circle.Equals(shape) || rectangle.Equals(shape) ||
                    triangle.Equals(shape))
                {
                    Console.WriteLine("{0}\tФигуры равны", shape);
                }
                else
                {
                    Console.WriteLine("{0}\tФигуры не равны", shape);
                }
            }

            Console.WriteLine("Для выхода нажмите Утеук...");
            Console.ReadLine();
        }