• JAVA题 矩形


     1 package com.lo;
     2 
     3 public class juxing {
     4     
     5     private double chang;
     6     
     7     private double kuan;
     8     
     9     public double getChang()
    10     {
    11         return chang;
    12     }
    13     public double getkuan()
    14     {
    15         return kuan;
    16     }
    17     public void setChang(double chang)
    18     {
    19         if (chang >0)
    20         {
    21         this.chang = chang;
    22         }
    23         else
    24         {
    25             System.out.println("长度值 " + chang + "无效");
    26         }
    27         }
    28     public void setKuan(double kuan)
    29     {
    30         if(kuan<=0)
    31         {
    32             System.out.println("宽度值 "+ kuan + "无效");
    33         }
    34         else
    35         {
    36             this.kuan = kuan;
    37         }
    38     }
    39     public juxing()
    40     {
    41         
    42     }
    43     public juxing(double chang,double kuan)
    44     {
    45         setChang(chang);
    46         setKuan(kuan);
    47     }
    48     public double getMianji()
    49     {
    50         return this.chang * this.kuan;
    51     }
    52     public static void main(String[]args)
    53     {
    54         juxing myJX = new juxing(2,7);
    55         
    56         myJX.chang = 12;
    57         
    58         System.out.println("矩形的面积 = "+myJX.getMianji());
    59     }
    60 }

    package com.lo;

    public class text1 {

    public static void main(String[] args) {

    juxing myJX1 = new juxing(20,6);

    System.out.println("长 = "+myJX1.getChang());

    System.out.println("宽 = "+myJX1.getkuan());

    System.out.println("矩形面积 ="+myJX1.getMianji());

    myJX1.setChang(30);

    myJX1.setKuan(15);

    System.out.println("矩形面积 ="+myJX1.getMianji());
    }
    }

  • 相关阅读:
    adb命令
    linux常用命令(2)
    Cisco路由器配置基本命令
    linux常用命令
    跨站脚本攻击xss
    选择合适的索引列顺序
    索引的选择性
    mysql索引类型(按存储结构划分)
    mysql数据类型优化
    vim基本命令总结
  • 原文地址:https://www.cnblogs.com/TENOKAWA/p/5243573.html
Copyright © 2020-2023  润新知