import java.util.Scanner;
class Demo_Rectangle {
public static void main(String[] args) {
Scanner sr = new Scanner(System.in);
System.out.println("请输入长方形的高: ");
int high = sr.nextInt();
System.out.println("请输入长方形的宽:");
int width = sr.nextInt();
Rectangle r = new Rectangle(high,width);
r.show();
}
}
class Rectangle {
private int high;
private int width;
public Rectangle(){}
public Rectangle(int high, int width){
this.high = high;
this.width = width;
}
public void setHigh(int high){
this.high = high;
}
public int getHigh(){
return high;
}
public void setWidth(int width){
this.width = width;
}
public int getWidth(){
return width;
}
public int getLength(){
return (width+high)*2;
}
public int getArea(){
return width*high;
}
public void show(){
System.out.println("周长为: " + getLength());
System.out.println("面积是: " + getArea());
}
}
|
|