概述
Bank类
public class Bank {
int savedMoney;
int year;
double interest;
double interestRate=0.29;
public double computerInterest(){
interest=year*interestRate*savedMoney;
return interest;
}
public void setInterestRate(double rate){
interestRate=rate;
}
}
ConstructionBank类
public class ConstructionBank extends Bank {
double year;
public double computerInterest(){
super.year=(int)year;
double r=year-(int)year;
int day=(int)(r*1000);
double yearInterest=super.computerInterest();
double dayInterest=day*0.0001*savedMoney;
interest=yearInterest+dayInterest;
System.out.printf("%d元存在建设银行%d年零%d天的利息:%f元n",savedMoney,super.year,day,interest);
return interest;
}
}
BankOfDalian类
public class BankOfDalian extends Bank {
double year;
public double computerInterest(){
super.year=(int)year;
double r=year-(int)year;
int day=(int)(r*1000);
double yearInterest=super.computerInterest();
double dayInterest=day*0.00012*savedMoney;
interest=yearInterest+dayInterest;
System.out.printf("%d元存在大连银行%d年零%d天的利息:%f元n",savedMoney,super.year,day,interest);
return interest;
}
}
SaveMoney类
public class SaveMoney {
public static void main(String[] args) {
int amount=8000;
ConstructionBank bank1=new ConstructionBank();
bank1.savedMoney=amount;
bank1.year=8.236;
bank1.setInterestRate(0.035);
double interest1=bank1.computerInterest();
BankOfDalian bank2=new BankOfDalian();
bank2.savedMoney=amount;
bank2.year=8.236;
bank2.setInterestRate(0.035);
double interest2=bank2.computerInterest();
System.out.printf("两个银行利息相差%f元n",interest2-interest1);
}
}
最后
以上就是神勇缘分为你收集整理的Java-银行计算利息的全部内容,希望文章能够帮你解决Java-银行计算利息所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复