public class SavingAccount {
public static double account = 3000
public static double rate = 0.03
public void update(double rate){
this.rate = rate
}
//flag 用来计算年利息和月利息,flag等true计算月利息
public double calc(double account , double rate , boolean flag){
if(flag)
return account * rate / 12
return account * rate
}
static class Test{
public static void main(String[] args) {
System.out.println("原始存款:"+SavingAccount.account + " \n原始利率:" +SavingAccount.rate )
SavingAccount sa = new SavingAccount()
System.out.println("原始年利息:"+sa.calc(SavingAccount.account,SavingAccount.rate,false))
System.out.println("原始月利息:"+sa.calc(SavingAccount.account,SavingAccount.rate,true))
System.out.println("######请输入新的利率######")
Scanner scanner = new Scanner(System.in)
sa.update(scanner.nextDouble())
System.out.println("更新后的利率:"+SavingAccount.rate)
System.out.println("更新后的年利息:"+sa.calc(SavingAccount.account,SavingAccount.rate,false))
System.out.println("更新后的月利息:"+sa.calc(SavingAccount.account,SavingAccount.rate,true))
//更新后的存款怎么算? 你是多长时间更新一次?
System.out.println("更新后的存款:"+(SavingAccount.account+sa.calc(SavingAccount.account,SavingAccount.rate,false)))
}
}
}
不知道对不对,我理解的是这样的了
等待保存。savingapplication即保存应用程序,idea卡在此页面说明文件太大,一时无法完全保存,只要耐心等待就好,若很长的时间idea依旧卡住,就只能重启电脑了,但之前的文件会全部清空。因为你把SavingAccount类放在了抽象类Account的里面,把它单独拿出来就好了!而且还有一个地方错了:s1.callInterest()调用的方法名错了,应该是s1.calInterest()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)