您的位置:首页 > 其它

用get和set取值来计算长方形的周长和面积(包括成员方法和构造方法)

2014-05-18 14:42 239 查看
public class Rectangle {
private int length;
private int width;
public Rectangle(){
}

public void setA(int length,int width){
this.length=length;
this.width=width;
}
public int getA(){
return this.length;
}
public int getA1(){
return this.width;
}
public int area(){
return length*width;
}
public int perimeter(){
return 2*(length+width);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Rectangle rectangle=new Rectangle();
rectangle.setA(2,3);
rectangle.getA();
rectangle.getA1();
rectangle.area();
rectangle.perimeter();
System.out.println("面积是"+rectangle.area());
System.out.println("周长是"+rectangle.perimeter());
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐