幼兒園裏打醬油
回答數: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());}}複製代碼