A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© Zzzack 中级黑马   /  2015-9-27 14:13  /  176 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

class Test_Rectangle {
        public static void main(String[] args) {
                Rectangle r = new Rectangle(10,20);
                System.out.println(r.getLength());
                System.out.println(r.getArea());
        }
}

class Rectangle {
        private int width;
        private int high;
        private int length;
        private int area;

        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 getLength() {
                return 2 * (width + high);
        }

        public int getArea() {
                return width * high;
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马