Reputation: 19
This is for C# Create a Rectangle class that holds width and height. Provide a constructor that accepts width and height. The Rectangle class contains three methods, to calculate the perimeter, to calculate the area, and to check whether it is square or not respectively.
public double width;
public double height;
public Rectangle(double w, double h)
{
width = w;
height = h;
}
public double perimeter()
{
return 2 * (width + height);
}
public double area()
{
return width * height;
}
public boolean isSquare()
{
if (width == height)
{
return true;
}
else
{
return false;
}
}
}
}
I get an error for this line
}
public boolean isSquare()
{
What is the problem?
Upvotes: 0
Views: 5272
Reputation: 4632
You should use bool
instead of boolean
. Try this code:
public bool isSquare()
{
if (width == height)
{
return true;
}
else
{
return false;
}
}
Hope it helps!
Upvotes: 3