展开全部
类Rectangle:public class Rectangle {
private double width;
private double height;
public Rectangle(){
32313133353236313431303231363533e59b9ee7ad9431333339663462
}
public Rectangle(double width , double height){
this.width = width;
this.height = height;
}
public double area(){
return width * height;
}
public double perimeter(){
return 2 * (width + height);
}
// getter and setter
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
}
类Test:public static void main(String[] args) {
Rectangle recOne = new Rectangle();
recOne.setWidth(200);
recOne.setHeight(100);
System.out.println("第一种方法计算周长和面积");
System.out.println("周长:" + recOne.perimeter());
System.out.println("面积:" + recOne.area());
Rectangle recTwo = new Rectangle(200 , 100);
System.out.println("第二种方法计算周长和面积");
System.out.println("周长:" + recTwo.perimeter());
System.out.println("面积:" + recTwo.area());
}