黑马程序员技术交流社区

标题: 求周长和面积的代码,面向对象的思想。 [打印本页]

作者: 刘文秀    时间: 2016-7-29 00:09
标题: 求周长和面积的代码,面向对象的思想。
class Homework3_Rectangle {
        public static void main(String[] args) {
               
                Rectangle r1 = new Rectangle();
                r1.setWidth(20);
                r1.setHigh(10);
                int zhou = r1.getZhou();
                double mian = r1.getMian();
       
                System.out.println(zhou + " " + mian);
               
                //System.out.println("周长是:" +r1.getZhou()  + "面积是:" +r1.getMian() );
               
                System.out.println(r1.getZhou());
                System.out.println(r1.getMian());
        }

}

class Rectangle {
        private int width;
        private int high;


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

        public double getMian() {
                return width * high;
        }
}       



作者: HelloKHM    时间: 2016-7-29 00:22
..................................
作者: 花陌相惜    时间: 2016-7-29 00:37
可以啊  为你点赞
作者: 刘文秀    时间: 2016-7-29 19:07
HelloKHM 发表于 2016-7-29 00:22
..................................

什么意思?
作者: 刘文秀    时间: 2016-7-29 19:08
花陌相惜 发表于 2016-7-29 00:37
可以啊  为你点赞

好的,谢谢啊
作者: accomplonely    时间: 2016-7-29 21:10
这个可以,很基础
作者: huangsong1002    时间: 2016-7-29 21:12
哇  ,这是什么,一个都看不懂.....
作者: walkk    时间: 2016-7-29 21:16
顶楼上,我也看不懂 我差不多已经是废人了




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2