早教吧作业答案频道 -->其他-->
(急用)创建一个Rectangle类,提供属性Length和Width,它们的默认值均为1.该类提供以下public方法:1.Perimeter方法,计算矩形的周长.2.Area方法,计算矩形的面积.3.IsSuqare方法,判断矩形是否是一个正方形.
题目详情
(急用)创建一个Rectangle类,提供属性Length和Width,它们的默认值均为1.该类提供以下public方法:
1.Perimeter方法,计算矩形的周长.
2.Area方法,计算矩形的面积.
3.IsSuqare方法,判断矩形是否是一个正方形.
属性的set方法应该确保不会将属性Length和Width设置为负值.
1.Perimeter方法,计算矩形的周长.
2.Area方法,计算矩形的面积.
3.IsSuqare方法,判断矩形是否是一个正方形.
属性的set方法应该确保不会将属性Length和Width设置为负值.
▼优质解答
答案和解析
/* C#版 */
class Rectangle
{
private Double _length;
private Double _width;
public Double Length
{
get { return _length; }
set { if (value < 0) throw new Exception("Length不能为负"); _length = value; }
}
public Double Width
{
get { return _width; }
set { if (value < 0) throw new Exception("Width不能为负"); _width= value; }
}
public Double Perimeter()
{
return 2 * (Length + Width);
}
public Double Area()
{
return Length * Width;
}
public Boolean IsSuqare()
{
return Length == Width;
}
}
class Rectangle
{
private Double _length;
private Double _width;
public Double Length
{
get { return _length; }
set { if (value < 0) throw new Exception("Length不能为负"); _length = value; }
}
public Double Width
{
get { return _width; }
set { if (value < 0) throw new Exception("Width不能为负"); _width= value; }
}
public Double Perimeter()
{
return 2 * (Length + Width);
}
public Double Area()
{
return Length * Width;
}
public Boolean IsSuqare()
{
return Length == Width;
}
}
看了(急用)创建一个Rectang...的网友还看了以下:
电容间的场强问题.U不变,当S变成原来的一半时,C和Q都小一倍,此时极板上单位面积带电量与S未变之 2020-05-13 …
连字成词(英语)l u o e b s r u s r e t o s w a e s r t e 2020-05-14 …
排列字母 组成单词 写出中文意思u s n e r e d s t n i t 2020-05-14 …
将字母组成单词,并译成汉语1.m,e,r,m,u,s,汉语2.u,l,t,e,c,u,r,汉语3. 2020-06-04 …
A.根据释义,拼写单词.1.costingalotofmoneyx,p,s,i,e,e,e,n,v 2020-06-10 …
小学简易方程用S表示路程,U表示速度,T表示时间,则S=UT,U=S/T,T=S/U.一辆汽车5小 2020-07-19 …
谁能给出满足下列条件的双线性映射e:G1×G2→Gt,其中G1,G2,Gt均为乘法循环群.要求是必 2020-07-30 …
1.N(u,o2),u,o2未知,(X1,X2)为e的样本,则可以成为统计量的是()A)X1+uB) 2020-10-31 …
一.看一看,将下列字母组成单词.1.t,o,e,f,n2.c,s,e,a,b,u,e3.l,e,p, 2020-10-31 …
电容器,给电容器冲点后断开电源,在相对绝缘的环境中(反正意思就是说电荷不被导走),可以知道两极板的电 2020-11-25 …