i am trying to solve this problem i dont know which object i need to refer to in my main method

using System;

namespace ShapesDemo
{
    abstract class GeometricFigure
    {
        static void Main(string[] args)
        {


        }
        public int height;
        public int width;
        public readonly double area;

        public int height
        {
            get { return height; }
            set { height = value; }
        }

        public int Width
        {
            get { return width; }
            set { width = value; }
        }
        public  abstract double  ComputeArea();
    }
        
    class Rectangle : GeometricFigure
    {
        public override double ComputeArea()
        {
            return width * height;

        }

    }
    class Square : Rectangle
    {
        public void equal(int height, int width)
        {
            if (height.Equals(width))
                Console.WriteLine("{0} for {1} has the same messers " +
                    height, width);

        }
    }

    class Triangle : GeometricFigure
    {
        public override double ComputeArea()
        {
            return width * (height / 2);

        }


    }
}

Recommended Answers

All 4 Replies

I don't think your main method belongs to the GeometricFigure class. The main method should go in the ShapesDemo class instead.

Having said that, your project description tells you to accept a GeometricFigure parameter to a method in which it's figures (height, width, area) is displayed. Your method signature should look like this:

private static void DisplayFigureDetails(GeometricFigure shape)

Then you can call the DisplayFigureDetails method for any class that extends the GeometricFigure class (ie Triangle, Rectangle or Square) by passing in your shape, for example:

Square square = new Square(8, 8);
DisplayFigureResults(square);

Hope this helps :)

thank you for your help, i kinda need some direction on where to put it ?

I would put the function in your ShapesDemo class along with the main method. Your main method should basically create a bunch of shapes with different sizes and call the DisplayFigureDetails method on each shape.

i am trying to solve it the way you said, i still have error with the square telling me

Shapes.Demo. Rectangle does not contain a constructor that take 0 argument

using System;

namespace ShapesDemo
{
      
    
    abstract class GeometricFigure
    {
       
         static void Main(string[] args)
        { Rectangle rectangle = new Rectangle(8,8);
            Square square = new Square(8,8);
           // DisplayFigureResults(square);
            Triangle triangle = new Triangle();
            Console.WriteLine("The Area is:", rectangle.ToString()); }

        public int height ;
        public int width ;
        public readonly double area;

        public int heigth
        {
            get { return height; }
            set { height = value; }
        }

        public int Width
        {
            get { return width; }
            set { width = value; }
        }
       // public double area
       // { get { return area; } }


       public abstract double ComputeArea();

       private static void DisplayFigureDetails(GeometricFigure shape)
        { }
      
     
    }
    class Rectangle : GeometricFigure
    {
        private int p;
        private int p_2;

        public Rectangle(int p, int p_2)
        {
            // TODO: Complete member initialization
            this.p = p;
            this.p_2 = p_2;
        }
        
        public override double ComputeArea()
        {
           Console.WriteLine("The Area is" + width.ToString(), height.ToString());
           return width * height;
         

        }

    }
    class Square : Rectangle
    {
        private int p;
        private int p_2;

        public  Square(int p, int p_2)
        {
            // TODO: Complete member initialization
            this.p = p;
            this.p_2 = p_2;
        }
        private static void DisplayFigureDetails(GeometricFigure Square) { }
        public void equal(int height, int width)
        {
            if (height.Equals(width))
                Console.WriteLine("{0} for {1} has the same messers " +
                    height, width);
        }
    }

    class Triangle : GeometricFigure
    {
       
        private static void DisplayFigureDetails(GeometricFigure Triangle){}
        public override double ComputeArea()
        {
            return width * (height / 2);

        }


    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.