zoukankan      html  css  js  c++  java
  • 银行计算利息

    package 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;
    	}
    }


    package bank;
    
    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元
    ",savedMoney,super.year,day,interest);
    		return interest;
    	}
    }
    
    package bank;
    
    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元
    ",savedMoney,super.year,day,interest);
    		return interest;
    	}
    
    }
    
    package bank;
    
    public class SaveMoney {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		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元
    ",interest2-interest1);
    	}
    }
    


  • 相关阅读:
    notepad++插件 small
    js中面向对象 small
    #九阴真经#优选配置渲染流程简要分析[Flexi引擎]
    gkENGINE HDR流程简析
    新的开始
    以前的一些画
    gkENGINE 开发两年半总结(上)
    gkENGINE跨平台的问题总结
    win7下安装xp双系统
    Hadoop0.20.2+ Nutch1.2+Tomcat7——分布式搜索配置
  • 原文地址:https://www.cnblogs.com/pangblog/p/3367665.html
Copyright © 2011-2022 走看看