编辑代码

public class Rectangle{
    private double width;
    private double height;
    public double area(){
        return width*height;
    }
    public double perimeter(){
        return (width+height)*2;
    }
    public Rectangle(){}
    public Rectangle(double width,double height){
        this.width=width;
        this.height=height;
    }
    public void setWidth(double width){
        this.width=width;
    }
    public double getWidth(){
        return width;
    }
    public double setHeight(double height){
        this.height=height;
    }
    public double getHeight(){
        return height;
    }
}
public class Test{
    public static void main(String... args){
        Rectangle a = new Rectangle();
        a.setWidth(width);
        a.setHeight(height);
        Rectangle b = new Rectangle(width,height);
        System.out.println(a.area());
        System.out.println(a.perimeter());
        System.out.println(b.area());
        System.out.println(b.perimeter());
    }
}