1 定义三个方法:getArea()求面积、getPer()求周长,showAll()分别在控制台输出长、宽、面积、周长。
2 有2个属性:长length、宽width
3 创建一个Rectangle对象,并输出相关信息
package kksk; public class kksk { int length; int width; public void getArea() { int a=width*length; System.out.println("面积"+a); } public void getPer() { int b=(width+length)*2; System.out.println("周长:"+b); } public void showAll() { System.out.println("宽:"+width); System.out.println("长"+length); getPer(); getArea(); } }
package kksk; public class Rectangle { public static void main(String[] args) { System.out.println("请输入长方形的长和宽:"); Rectangle r = new Rectangle(); r.getArea(); r.getPer(); r.showAll(); } private void showAll() { // TODO Auto-generated method stub } private void getPer() { // TODO Auto-generated method stub } private void getArea() { // TODO Auto-generated method stub } }