class Rectangle{
private int length;
private int width;
public Rectangle(int length,int width){
this.length=length;
this.width=width;
}
public void set(int length,int width){
this.length=length;
this.width=width;
}
public void get(){
System.out.println("此长方形的长为"+length+"宽为"+width);
}
public int getLength(){
return length;
}
public int getWidth(){
return width;
}
public int calculatePerimeter(){
return 2*(length+width);
}
public int calculateArea(){
return (length*width);
}
public void print(){
System.out.println("此长方形的周长为"+calculatePerimeter()+"面积为"+calculateArea());
}
}
class Test{
public static void main(String [ ] args){
Rectangle myrectangle=new Rectangle(15,10);
myrectangle.get();
myrectangle.print();
myrectangle.set(20,15);
System.out.println("长方形的长是"+myrectangle.getLength()+"宽是"+ myrectangle
设计一个长方形类
最新推荐文章于 2024-04-14 12:05:10 发布