zoukankan      html  css  js  c++  java
  • 第七周作业

    定义一个矩形类Rectangle:(知识点:对象的创建和使用)
    1 定义三个方法:getArea()求面积、getPer()求周长,showAll()分别在控制台输出长、宽、面积、周长。
    2 有2个属性:长length、宽width
    3 创建一个Rectangle对象,并输出相关信息

    package chap01;
    
    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("面积");
            getArea();
            System.out.println("周长");
            getPer();
        }
    
    }
    package chap01;
    
    import java.util.*;
    
    public class Test01 {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Rectangle p1 = new Rectangle();
    
            Scanner input = new Scanner(System.in);
            System.out.println("长");
            p1.length = input.nextInt();
    
            System.out.print("宽");
            p1.width = input.nextInt();
            p1.showAll();
    
        }
    
    }
  • 相关阅读:
    工作中Linux常用命令
    自动化测试
    Firefox/Chrome WebDriver浏览器驱动
    Appium
    Python+selenium进行浏览器的连接ChromeOptions
    文件及异常捕获处理
    面向对象练习题
    python函数&面向对象
    python基础
    python8道练习题
  • 原文地址:https://www.cnblogs.com/527x/p/12733093.html
Copyright © 2011-2022 走看看