Ejemplo n.º 1
0
    public static void Main()
    {
        Shape circle1 = new Circle(5);

        Shape triangle1 = new Triangle(10, 14, 20, 6.49);
        Shape triangle2 = new Triangle(15, 15, 15, 12.9);
        Shape triangle3 = new Triangle(12, 12, 15, 9.36);

        Shape quadrilateral1 = new Quadrilateral(30, 30);
        Shape quadrilateral2 = new Quadrilateral(15, 40);

        List <Shape> shapeList = new List <Shape>()
        {
            circle1, triangle1, triangle2, triangle3, quadrilateral1, quadrilateral2
        };

        foreach (Shape s in shapeList)
        {
            Console.WriteLine("Name of Shape: " + s.getName());
            Console.WriteLine("Perimeter of " + s.getName() + ": " + s.getPerimeter());
            Console.WriteLine("Surface Area of " + s.getName() + ": " + s.getSurfaceArea());
            Console.WriteLine("\n");
        }

        Console.WriteLine("\nSorted by Surface Area:");
        var sortedByArea = ShapeOperations.sortByField(shapeList, "surfaceArea");

        foreach (Shape s in sortedByArea)
        {
            Console.WriteLine("Name of object Shape: " + s.getName());
        }

        var sortedByPerimeter = ShapeOperations.sortByField(shapeList, "perimeter");

        Console.WriteLine("\nSorted by Perimeter:");
        foreach (Shape s in sortedByPerimeter)
        {
            Console.WriteLine("Name of object Shape: " + s.getName());
        }


        Console.WriteLine(ShapeOperations.serializeShapes(shapeList));

        Console.WriteLine("Total number of Shape Objects in  the memory: " + Shape.GetActiveInstances());

        Console.ReadLine();
    }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Cat Cadife = new Cat("Cadife", 'F', "Calico");

            Cadife.printGreetings();
            Petshop.AddCat(Cadife);

            Console.WriteLine("Let there be snakes!");
            Mamba     mamba     = new Mamba();
            CornSnake cornSnake = new CornSnake();

            Console.WriteLine(Snake.Poisonous);     //True
            Console.WriteLine(Mamba.Poisonous);     //True
            Console.WriteLine(CornSnake.Poisonous); //False
            Console.WriteLine(mamba.greeting);      //"Hello from Animal!"
            Console.WriteLine(cornSnake.greeting);  //"Hello from Animal!"

            mamba.Length = 150;                     //The length of a snake cannot exceed 100!
            mamba.Length = 30.2768f;
            Console.WriteLine(mamba.Length);        //30.28

            IShape triangle = new Triangle(1, 2);

            Console.WriteLine(ShapeOperations.DoubleAndRoundArea(triangle)); //2

            Customer annaCustomer     = new ("Anna", "Karenina");
            Customer annaCustomerCopy = new ("Anna", "Karenina");

            Console.WriteLine(annaCustomer == annaCustomerCopy); //True
            Console.WriteLine(annaCustomer);                     //Customer { FirstName = Anna, LastName = Karenina }

            Customer annaChanged = annaCustomer with {
                FirstName = "Anneta"
            };

            Console.WriteLine(annaCustomer == annaChanged); //False

            BusinessCustomer annaBusinessCustomer = new("Anna", "Karenina", "Perfumes Corp");

            Console.WriteLine(annaCustomer == annaBusinessCustomer); //False because annaCustomer does not include the BusinessName field
        }
    }