用Rectangle输出一个矩形的周长和面积

/*
 * 用Rectangle输出一个矩形的周长和面积
 */ 用Rectangle输出一个矩形的周长和面积_第1张图片
public class Rectangle {
private int width;
private int height;
public static void main(String[] args) {
//声明变量
Rectangle rec = new Rectangle(36,21);
System.out.println("这个矩形的周长是:"+rec.getPerimeter());
System.out.println("这个矩形的面积是:"+rec.getArea());
}
public int getPerimeter(){
return this.width *2 + this.height *2;
}
//获得矩形的周长
public int getArea(){
return this.width * this.height;
}
//获得矩形的面积
public Rectangle(int width,int height) {
super();
this.width = width;
this.height = height;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}

你可能感兴趣的:(用Rectangle输出一个矩形的周长和面积)