幼儿园里打酱油
回答数:216 | 被采纳数:139
2017-03-11 08:02:23
class SavingAccount
{
private static doublenlxi;//存储年利率
privatedouble cke; //定义存储存款额
public voidsetCKE(double c)
{
cke=c;
}
public double getCKE()
{
return cke;
}
public void setNLiXi(double n)
{
nlxi=n;
}
//提供计算年利息的方法
public double getNLiXi()
{
return cke*nlxi;
}
//提供月利息的方法
public double getYLixi()
{
return(cke*nlxi)/12;
}
public static void main(String[] args)
{
SavingAccount saver=new SavingAccount();//定义一个方法的对象名
saver.setCKE(3000.0);
saver.setNLiXi(0.03);
saver.getNLiXi();
saver.getYLiXi();
System.out.println( saver.setCKE());
System.out.println(saver.getNLiXi());
System.out.println(saver.getYLiXi());
}
}
这是我的原代码
青岛安工护栏网
回答数:194 | 被采纳数:74
2017-03-11 08:12:57
你试下看这个
public class SavingAccount {private static final int MONTH_NUMBER = 12;private double nlxi;//存储年利率private double cke; //存储存款额public void setCKE(double cke) {this.cke = cke;}public double getCKE() {return this.cke;}public void setNLiXi(double nlxi) {this.nlxi = nlxi;}//提供计算年利息的方法public double getNLiXi() {return cke * nlxi;}//提供月利息的方法public double getYLixi() {return this.getNLiXi() / MONTH_NUMBER;}public static void main(String[] args) {SavingAccount saver = new SavingAccount();double cke = 3000.0D;double nlixi = 0.03D;saver.setCKE(cke);saver.setNLiXi(nlixi);System.out.println("存储存款额: " +cke+ "存储年利率:" +nlixi);System.out.println("年利息: " +saver.getNLiXi());System.out.println("月利息: " +saver.getYLixi());}}复制代码