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 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);

}

}
}``````
Attachments
2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by shyla

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 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);

}

}
}``````

Edited by shyla: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.