super 简单用法
package Bank;
public class Bank {
double year = 5.216 ;
double savedMoney = 50000;
Bank(){
}
Bank(double a,double b){
year = a;
savedMoney = b;
}
double computerInterest() {
double interest;
interest=year*0.035*savedMoney;
return interest;
}
public static void main(String args[])
{
Bank B1 = new Bank();
BankOfQingdao B2 = new BankOfQingdao();
ConstructionBank B3 = new ConstructionBank();
System.out.println("原银行利息:"+B1.computerInterest());
System.out.println("青岛银行利息:"+B2.computerInterest());
double a = B2.computerInterest();
System.out.println("建设银行利息:"+B3.computerInterest());
double b = B3.computerInterest();
System.out.println("两者的差值为:"+(a-b));
BankOfCommerce B4 = new BankOfCommerce(8.236,8000.0);
System.out.println("商业银行利息:"+B4.computerInterest());
}
}
```package Bank;
public class BankOfCommerce extends Bank{
BankOfCommerce(double a,double b)
{
super.year =a;
super.savedMoney = b;
}
double computerInterest() {
double interest;
double day = super.year-(int)Math.floor(super.year);
// System.out.println(day);
//System.out.println(savedMoney);
super.year = (int)Math.floor(super.year);
interest=day*0.00012*savedMoney*1000+super.computerInterest();
return interest;
}
}
```package Bank;
public class BankOfQingdao extends Bank{
double computerInterest() {
double interest;
double day = super.year-(int)Math.floor(super.year);
interest=day*0.00015*savedMoney*1000+super.computerInterest();
return interest;
}
}
```package Bank;
public class ConstructionBank extends Bank{
double computerInterest() {
double interest;
double day = super.year-(int)Math.floor(super.year);
interest=day*0.00010*savedMoney*1000+super.computerInterest();
return interest;
}
}
在这里插入代码片