设计并测试一个名为Retangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积
2010-12-08
展开全部
public class Rectangle
{
private Point _bottomLeft = Point.Empty;
private Point _topRight = Point.Empty;
public Point BottomLeft
{
get
{
return this._bottomLeft;
}
set
{
this._bottomLeft = value;
}
}
public Point TopRight
{
get
{
return this._topRight;
}
set
{
this._topRight = value;
}
}
public int GetArea()
{
if (this._bottomLeft == this._topRight)
{
return 0;
}
int width = this._topRight.X - this._bottomLeft.X;
int heigth = this._bottomLeft.Y - this._topRight.Y;
return width * heigth;
}
{
private Point _bottomLeft = Point.Empty;
private Point _topRight = Point.Empty;
public Point BottomLeft
{
get
{
return this._bottomLeft;
}
set
{
this._bottomLeft = value;
}
}
public Point TopRight
{
get
{
return this._topRight;
}
set
{
this._topRight = value;
}
}
public int GetArea()
{
if (this._bottomLeft == this._topRight)
{
return 0;
}
int width = this._topRight.X - this._bottomLeft.X;
int heigth = this._bottomLeft.Y - this._topRight.Y;
return width * heigth;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询