编辑代码

package FristJspHomework;

/**
 * 9、编写一个类,类名为Rectangle(矩形),
 * 它有两个整型的变量width(宽)和height(高);
 * 有一个方法area(),没有参数,返回类型为double,功能是求矩形的面积;
 * 还有另一个方法为perimeter()没有参数,返回类型为double,功能是求矩形的周长,
 */
public class RectangleTest {
	/**
	 * 宽
	 */
	int with;
	/**
	 * 高
	 */
	int height;

	/**
	 * area()方法,求矩形的面积
	 * @return 返回面积
	 */
	public double area() {
		this.with = 5;
		this.height = 10;
		return with * height;
	}
	
	/**
	 * perimeter()方法,求矩形周长
	 * @return
	 */
	public double perimeter(){
		this.with = 5;
		this.height = 10;
		return (with + height) * 2;
	}
	
	/**
	 * 测试方法
	 */
	public static void main(String[] args) {
		/**
		 * 创建RectangleTest对象
		 */
		RectangleTest r = new RectangleTest(); 
		
		double retArea = r.area();
		System.out.println("矩形的面积-->" + retArea);
		
		double retPerimeter = r.perimeter();
		System.out.println("矩形的周长-->" + retPerimeter);
	}
}