package Rectangle;
public class Rectangle{
private double length;
private double width;
private static int id;
private double mianji;
private double zhouchang;
public Rectangle(){
}
public Rectangle(double length,double width){
this.length =length;
this.width = width;
}
public double computemianji(double length,double width) {
mianji=length*width;
return mianji;
}
public double computezhouchang(double length,double width) {
zhouchang=(length+width)*2;
return zhouchang;}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public String toString() {
return "长度为"+length+"宽度为"+width;
}
static int id() {
return id;
}
static {
id=1;
}
}
下面是main
package Rectangle;
public class 矩形 {
public static void main(String[] args) {
Rectangle one = new Rectangle(2.5,4);
System.out.println("当长为4,宽为2.5时矩形的面积为"+one.computemianji(2.5,4));
Rectangle two = new Rectangle(10,30);
System.out.println("当长为30,宽为10时矩形的周长为"+two.computezhouchang(10,30));
Rectangle three = new Rectangle(4,10);
three.setWidth(4);
three.setLength(10);
System.out.println("矩形的长为"+three.getWidth()+"矩形的宽为"+three.getLength());
Rectangle five = new Rectangle(4,10);
System.out.println(five.toString());
Rectangle six = new Rectangle(4,10);
System.out.println(six.id());
Rectangle seven = new Rectangle();
System.out.println(seven);
}
}