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)))
}
}
}
不扮高穗知道对不对,我理解的是这样的了
鄙视楼上,你也是从小白出来的#include "stdio.h"
void main()
{
float s,i
printf("请设置年利率:\n")
scanf("%f",&i)
printf("档袭察请设行茄置总额:\n")
scanf("%f",&s)
s+=s*i*0.01
printf("禅胡总额是:%f\n",s)
}
测试:
请设置年利率:
2
请设置总额:
5000
总额是:
5100.000000
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)