该楼层疑似违规已被系统折叠隐藏此楼查看此楼
publicinterfaceplaneGraphics2
{
publicabstractdoublearea();
publicabstractdoubleperimeter();
publicabstractvoidprint();
}
publicclassrectangle2implementsplaneGraphics2
{
protecteddoublelength;
protecteddoublewidth;
publicrectangle2(doublelength,doublewidth)
{this.length=length;
this.width=width;
}
publicrectangle2(doublewidth)
{
this.length=width;
this.width=width;
}
publicrectangle2(0
{
this(0,0);
}
publicrectangle2(rectangle2r1)
{this(r1.length,r1.width);
}
publicdoublearea()
{
returnthis.width*this.length;
}
publicdoubleperimeter()
{
return(this.width+this.length)*2;
}
publicvoidprint()
{
if(this.length==this.width)
system.out.println("一个矩形。边长为"+this.length);
else
system.out.print("一个长方形,长度为"+this.length+",宽度"+this.width);
system.out.println(",面积为"+this.area()+",周长为"+this.perimeter());
}
publicstaticvoidmain(stringargs[])
{
rectangle2r1=newrectangle2(10,20);
r1.print();
r1=newrectangle2(10);
r1.print();
}
}