weixin_51531948 2021-06-24 20:12 采纳率: 50%
浏览 7

如何完整的完成,还有后续包如何导入

设计一个表示矩形的类Rect,其矩形数据成员有长 floatLength ,宽float Width,设计相应成员方法,实现下列功能:
1构造方法初始化长和宽。
②设计改变长和宽的成员方法,并设计获得长和宽的成员方法,
③计算并返回长方形的周长
④计算并返回长方形的面积。
⑤将该类封装为jar包。

  • 写回答

1条回答 默认 最新

  • 夜郎king 2022博客之星IT其它领域TOP 12 2022-11-03 08:13
    关注

    参考代码如下:

    package com.yelang.case4;
    
    public class Rect {
    
        private float length;
    
        private float width;
    
        public float getLength() {
            return length;
        }
    
        public void setLength(float length) {
            this.length = length;
        }
    
        public float getWidth() {
            return width;
        }
    
        public void setWidth(float width) {
            this.width = width;
        }
    
        public Rect() {
            super();
        }
    
        public Rect(float length, float width) {
            super();
            this.length = length;
            this.width = width;
        }
    
        public float getArea() {
            return this.length * this.width;
        }
    
        public float getRound() {
            return (this.length + this.width) * 2;
        }
    
        public static void main(String[] args) {
            Rect rect = new Rect(5.1F, 6F);
            System.out.println(rect.getLength());
            System.out.println(rect.getArea());
            System.out.println(rect.getRound());
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表