import java.util.Scanner;
public class Test_Rectangle {
/**
* @param args
*/
public static void main(String[] args) {
Rectangle r = new Rectangle();
Scanner sc = new Scanner(System.in);
System.out.println("请输入长方形的高:");
r.setHigh(sc.nextInt());
System.out.println("请输入长方形的宽:");
r.setWidth(sc.nextInt());
System.out.print("长方形的面积是:");
System.out.println(r.getArea());
System.out.println("长方形周长是:" + r.getPerimeter());
}
}
public class Rectangle {
private int width;
private int high;
public int getWidth() {
return width;
}
public void setWidth(int width) {
if(width > 0 ){
this.width = width;
}
}
public int getHigh() {
return high;
}
public void setHigh(int high) {
if(high > 0){
this.high = high;
}
}
public int getArea(){
return width*high;
}
public int getPerimeter(){
int perimeter = (high + width) * 2;
return perimeter;
}
}
|