publicabstractclassbank{
publicabstractdoublegetTotal(doublemoney,intyears,doubleinterest);
}
publicclassgeneralBankextendsbank{
publicdoublegetTotal(doublemoney,intyears,doubleinterest){
doubletotal=money*years*(interest)+money;
//将double类型转化为decimal防止double运算精度显示错误
java.text.DecimalFormatdecimalFormat=newjava.text.DecimalFormat("0.00");
total=Double.parseDouble(decimalFormat.format(total));
returntotal;
}
}
publicclasstest{
publicstaticvoidmain(String[]args){
bankbank=newgeneralBank();
doubletotal=bank.getTotal(10000,1,0.03);
System.out.println(total);
}
}