....................
package XX;
public class Rectangle {
private double length;
private double width;
public double area;
public double perimeter;
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getArea() {
return area;
}
public void setArea(double area) {
this.area = area;
}
public double getPerimeter() {
return perimeter;
}
public void setPerimeter(double perimeter) {
this.perimeter = perimeter;
}
}
..........----》》》》》》
package XX;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
double length ;
double width;
Rectangle n=new Rectangle();
Scanner sc =new Scanner(System.in);
System.out.println("请输入长方形的长");
double x=sc.nextDouble();
n.setLength(x);
System.out.println("请输入长方形的宽");
double y=sc.nextDouble();
n.setWidth(y);
n.setArea(x*y);
n.setPerimeter(2*(x+y));
System.out.println("面积为:"+n.getArea());
System.out.println("周长为"+n.getPerimeter());
}
}