class Homework3_Rectangle {
public static void main(String[] args) {
Rectangle r1 = new Rectangle();
r1.setWidth(20);
r1.setHigh(10);
int zhou = r1.getZhou();
double mian = r1.getMian();
System.out.println(zhou + " " + mian);
//System.out.println("周长是:" +r1.getZhou() + "面积是:" +r1.getMian() );
System.out.println(r1.getZhou());
System.out.println(r1.getMian());
}
}
class Rectangle {
private int width;
private int high;
public Rectangle() {} //无参构造
public Rectangle(int width,int high) {
this.width = width;
this.high = high;
}
public void setWidth(int width) {
this.width = width;
}
public int getWidth() {
return width;
}
public void setHigh(int high) {
this.high = high;
}
public int getHigh() {
return high;
}
public int getZhou() {
return 2 * (width + high);
}
public double getMian() {
return width * high;
}
}
|
|