JAVA,
分享于 点击 12098 次 点评:266
JAVA,
import java.util.Scanner; //引入Scanner类,负责从键盘接收数据public class Power {
double lastRecord;
double currentRecord;
double usedAmount;
double usedFee;
public void setRecord(){
Scanner scan=new Scanner(System.in);
System.out.print("请输入上月用电数:");
lastRecord=scan.nextInt(); //读入一个字符串
System.out.printf("请输入本月用电数:");
currentRecord=scan.nextInt(); //读入一个int型整数
//System.out.printf("已经输入上月用电数s=%s\n",lastRecord);
//System.out.printf("已经输入本月用电数i=%d\n",currentRecord);
}
public void showRecord(){
System.out.printf("\n所有输入的数据:\n上月用电数:"+lastRecord+"\n本月用电数:"+currentRecord);
}
public double calcUsedAmount(){
usedAmount=currentRecord-lastRecord;
System.out.println("本月用电数"+usedAmount);
return usedAmount;
}
public void calcUsedFee(){
usedFee=1.2*usedAmount;
System.out.println("本月用电费"+usedFee);
}
public static void main(String[] args) {
Power du=new Power();
du.setRecord();
du.showRecord();
du.calcUsedAmount();
du.calcUsedFee();
}
}
相关文章
- 暂无相关文章
用户点评