代码如下:


import java.util.Scanner;
public class Record {
double lastRecord;//上月用电数
double curentRecod;//本月用电数
double usedAmount;//本月用电量
double usedFee;//本月电费
//获取上月和本月的用电数
public void setRcord() {
Scanner scan=new Scanner(System.in);
System.out.print("请输入上月用电量:");//
lastRecord=scan.nextInt();
System.out.print("请输入本月用电量:");//
curentRecod=scan.nextInt();
}//键盘获取数据
//计算本月的用电量
public double calcUsedAmount() {
usedAmount=curentRecod-lastRecord;
System.out.println("本月用电量:"+usedAmount);
return usedAmount;
}
//计算本月的电费
public double calcUsedFee() {
usedFee=1.2*usedAmount;
System.out.println("本月电费"+usedFee);
return usedFee;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Record Free=new  Record ();//声明并创建card类的对象free
Free.setRcord();//通过对象free调用card类的方法setRcord()
Free.calcUsedAmount();//通过对象free调用card类的方法calcUsedAmount()
Free.calcUsedFee();//通过对象free调用card类的方法calcUsedFee()
}
}

效果图:

电费计算

相关文章:

  • 2022-12-23
  • 2021-08-12
  • 2021-12-24
  • 2022-02-05
  • 2022-12-23
  • 2022-03-05
  • 2021-08-31
  • 2021-06-19
猜你喜欢
  • 2021-05-23
  • 2021-11-28
  • 2021-12-28
  • 2022-01-07
  • 2021-05-14
  • 2021-09-20
  • 2021-10-16
相关资源
相似解决方案