zoukankan      html  css  js  c++  java
  • JAVA-1.5-homework

    package study;//创建类
    /*
     * 定义一个矩形类Rectangle:(知识点:对象的创建和使用)
     *1 定义三个方法:getArea()求面积、getPer()求周长,showAll()分别在控制台输出长、宽、面积、周长。
     *2 有2个属性:长length、宽width
     *3 创建一个Rectangle对象,并输出相关信息
     */
    public class Rectangle {
        double length;
        double width;
        public void getArea(){
            System.out.println("面积是:"+length*width);
        }
        public void getPer(){
            System.out.println("周长是:"+(length+width)*2);
        }
        public void showAll(){
            System.out.println("长是:"+length);
            System.out.println("宽是:"+width);
            getArea();
            getPer();
        }
    }
     
    package study;//创建类
    /*
     * 定义一个矩形类Rectangle:(知识点:对象的创建和使用)
     *1 定义三个方法:getArea()求面积、getPer()求周长,showAll()分别在控制台输出长、宽、面积、周长。
     *2 有2个属性:长length、宽width
     *3 创建一个Rectangle对象,并输出相关信息
     */
    public class Rectangle {
        double length;
        double width;
        public void getArea(){
            System.out.println("面积是:"+length*width);
        }
        public void getPer(){
            System.out.println("周长是:"+(length+width)*2);
        }
        public void showAll(){
            System.out.println("长是:"+length);
            System.out.println("宽是:"+width);
            System.out.println("面积是:"+length*width);
            System.out.println("周长是:"+(length+width)*2);
        }
    }
    package study;//创建对象
    
    public class homework {
        public static void main(String[] args) {
            Rectangle Rectangle=new Rectangle();
            Rectangle.length=3;
            Rectangle.width=4;
            Rectangle.showAll();
        }
    }
    //运行结果
  • 相关阅读:
    Spark中文指南(入门篇)-Spark编程模型(一)
    Scala入门学习笔记三--数组使用
    沃老师学生的成绩
    Codeforces Round #461 (Div. 2) DRobot Vacuum Cleaner
    Codeforces Round #461 (Div. 2) ABC
    Educational Codeforces Round 37 (Rated for Div. 2) ABC
    Codeforces Round #460 (Div. 2) D Substring
    Codeforces Round #460 (Div. 2) ABC
    中缀式转后缀式求表达式结果
    计算器——python正则表达式
  • 原文地址:https://www.cnblogs.com/yunlan/p/12733178.html
Copyright © 2011-2022 走看看