zoukankan      html  css  js  c++  java
  • 第四次上机

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

         调用setXXX()方法初始化对象;
    
         假设每度电的价格为1.2元,计算并显示本月电费。
    

    创建对象二:上月电表读数1200,本月电表读数为1450。
    要求:调用2个参数的构造方法创建并初始化对象;

    调用setXXX()方法修改本月电表读数为1500(模拟读错了需修改);

    假设每度电的价格为1.2元,计算并显示本月电费。
    package qwe;
    public class Ewq {
    private int premonth;
    private int curmonth;
    public Ewq(){
    }
    public Ewq(int premonth,int curmonth){
    this.premonth=premonth;
    this.curmonth=curmonth;
    }
    public void setpremonth(int premonth){
    this.premonth=premonth;
    }
    public int getpremonth(){
    return premonth;
    }
    public void setcurmonth(int curmonth){
    this.curmonth=curmonth;
    }
    public int getcurmonth(){
    return curmonth;
    }
    public void myprint() {
    System.out.println("上月电表读数:"+premonth+"本月电表读数:"+curmonth);
    }
    }
    package qwe;
    public class Qwe {
    public static void main(String[] args) {
    Ewq s1=new Ewq();
    s1.setpremonth(1000);
    s1.setcurmonth(1200);
    s1.myprint();
    System.out.println("本月电费:"+(s1.getcurmonth()-s1.getpremonth())1.2);
    Ewq s2=new Ewq(1200,1450);
    s2.setcurmonth(1500);
    s2.myprint();
    System.out.println("本月电费:"+(s2.getcurmonth()-s2.getpremonth())
    1.2);
    }
    }

  • 相关阅读:
    BZOJ2648: SJY摆棋子
    BZOJ1925: [Sdoi2010]地精部落
    BZOJ1941: [Sdoi2010]Hide and Seek
    BZOJ2434: [Noi2011]阿狸的打字机
    BZOJ3295: [Cqoi2011]动态逆序对
    BZOJ1406: [AHOI2007]密码箱
    BZOJ1115: [POI2009]石子游戏Kam
    BZOJ1531: [POI2005]Bank notes
    BZOJ2730: [HNOI2012]矿场搭建
    计算几何《简单》入土芝士
  • 原文地址:https://www.cnblogs.com/6825186a/p/10804451.html
Copyright © 2011-2022 走看看