Ejemplo n.º 1
0
        private static BadRectangle CreateBadRectangle(int length, int width)
        {
            BadRectangle rectangle = new BadRectangle();

            rectangle.length = length;
            rectangle.width  = width;
            return(rectangle);
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            // Part 1
            BadRectangle smallRectangle = CreateBadRectangle(4, 5);

            DescribeBadRectangle(smallRectangle);
            CalculateAndDisplayArea(smallRectangle);

            // Part 2
            Rectangle[] rectangles = new Rectangle[] {
                new Rectangle(8, 5),
                new Rectangle(5, 3),
                new Rectangle(20, 10),
            };
            for (int i = 0; i < rectangles.Length; i++)
            {
                Console.WriteLine();
                Console.WriteLine($"- Rectangle {i + 1}");
                Console.WriteLine(rectangles[i]);
                Console.WriteLine($"Area: {rectangles[i].GetArea()}");
            }
        }
Ejemplo n.º 3
0
        private static void CalculateAndDisplayArea(BadRectangle rectangle)
        {
            int area = rectangle.width * rectangle.length;

            Console.WriteLine($"The area of the bad rectangle is {area}.");
        }
Ejemplo n.º 4
0
 private static void DescribeBadRectangle(BadRectangle rectangle)
 {
     Console.WriteLine(
         $"BadRectangle {{ length: {rectangle.length}, width: {rectangle.width} }}");
 }