• 第四次上机课


    1. 编写“电费管理类”及其测试类。
    • 第一步 编写“电费管理”类
    • 私有属性:上月电表读数、本月电表读数
    • 构造方法:无参、2个参数
    • 成员方法:getXXX()方法、setXXX()方法
    • 成员方法:显示上月、本月电表读数
    • 第二步 编写测试类
    • 创建对象一:上月电表读数为1000,本月电表读数为1200。

       要求:调用无参构造方法创建对象;

             调用setXXX()方法初始化对象;

             假设每度电的价格为1.2元,计算并显示本月电费。

    package 编写电费管理类及测试类;
    
    public class Electricity { 
        private double lastmElc;
        private double thismElc;
        Electricity() {
            
        }
        Electricity(double lastmElc,double thismElc) {
            this.lastmElc=lastmElc;
            this.thismElc=thismElc;
        }
        double getlastmElc() {
            return this.lastmElc;
        }
        double getthismElc() {
            return this.thismElc;
        }
        void setlastmElc(double lastmElc) {
            this.lastmElc=lastmElc;
        }
        void setthismElc(double thismElc) {
            this.thismElc=thismElc;
        }
        void showElc() {
            System.out.println("上月电表读数为:"+this.lastmElc);
            System.out.println("本月电表读数为:"+this.thismElc);
        }
    }
    
    public class TestElectricity {
    
        public static void main(String[] args) {
        
            Electricity a=new Electricity();
            a.setlastmElc(1000);
            a.setthismElc(1200);
            a.showElc();
            System.out.println("本月电费为:"+(a.getthismElc()-a.getlastmElc())*1.2);
            Electricity b=new Electricity(1200,1450);
            b.setthismElc(1500);
            b.showElc();
            System.out.println("本月电费为:"+(b.getthismElc()-b.getlastmElc())*1.2);
        }
    
    }
  • 相关阅读:
    dotnet core 3.0 linux 部署小贴士
    Akka.net 性能测试兼使用小技巧
    如何给小学生讲清楚ECC椭圆曲线加密
    Typescript骚操作,在TS里面直接插入HTML
    源自于NEO的KeyValue 数据库面世啦
    编译ROCKSDB总结
    Windows linux子系统 使用说明
    dotnetcore http服务器研究(二)性能分析
    dotnetcore Http服务器研究(一)
    使用信号量来 限制无边界池子与队列
  • 原文地址:https://www.cnblogs.com/qq602671387/p/10773503.html
Copyright © 2020-2023  润新知