编写以下要求的程序:
(1)创建Rectangle类,添加width和height两个成员变量
(2)在Rectangle类中,添加两种方法分别计算矩形的周长和面积
(3)main() 函数中输出面积和周长
public class Rectangle{
double width;
double height;
Rectangle(double w,double h){
width = w;
height = h;
}
public double getPerimeter(){
return (width+height)*2;
}
public double getArea(){
return width*height;
}
public static void main(String[] args) {
double w=Double.parseDouble(args[0]);
double h=Double.parseDouble(args[1]);
Rectangle rect= new Rectangle(w,h);
System.out.println(rect.getPerimeter());
System.out.println(rect.getArea());
}
}