• 4.17作业


    定义一个矩形类Rectangle:(知识点:对象的创建和使用)

    1 定义三个方法:getArea()求面积、getPer()求周长,showAll()分别在控制台输出长、宽、面积、周长。

    2 2个属性:长length、宽width

    3 创建一个Rectangle对象,并输出相关信息

     1 package chap;
     2 public class Rectangle {
     3        int length;
     4        int width;
     5     
     6         public void getArea() {
     7             System.out.println(length*width);
     8         }
     9         public void getPer() {
    10             System.out.println((length+width)*2);
    11         }
    12         public void showAll() {
    13             System.out.println("长"+lenght);
    14             System.out.println("宽"+width);
    15             System.out.println("面积:");
    16         getArea();
    17         System.out.println("周长");
    18         getPer();
    19         }
    20 }  
    21 
    22 package chap;
    23 
    24 import java.util.Scanner;
    25 
    26 public class test1 {
    27 
    28     public static void main(String[] args) {
    29         // TODO Auto-generated method stub
    30      Rectangle R= new Rectangle();
    31      Scanner input =new Scanner(System. in);
    32      System.out.println("请输入长");
    33      R.lenght=input.nextInt();
    34      System.out.println("请输入宽");
    35      R.width=input.nextInt();
    36      R.showAll();
    37      
    38     }
    39 
    40 }
  • 相关阅读:
    ASP.NET 概述
    用vs调试项目页面无样式
    eniac世界第二台计算机
    汇编语言
    操作系统发展史
    网站架构发展
    简单分布式系统构建知识
    Android常用adb命令
    USB 3.0规范中译本 第4章 超高速数据流模型
    ECMAScript 6 &ECMAScript 5(在线手册)
  • 原文地址:https://www.cnblogs.com/WangYYY/p/12736282.html
Copyright © 2020-2023  润新知