Math.sqrt(x)
s.toUpperCase
double balance = futureValue(rate);
public static double futureValue(double p) {
...
}
ㄒ肈: Futval.java (﹍絏)
ㄒいㄧ计 futureValue蹿肂㎝计常㏕﹚ эΘ狡ㄏノ(reusable)把计临惠糤肂㎝计
public static double futureValue(double initBalance,
double p, int nyear) {
double b = initBalance
* Math.pow(1 + p / (12 * 100), 12 * nyear);
return b;
}
/**
* computes the value of an investment with compound interest
* @param initBalance the initial value of the investment
* @param p the interest rate in percent
* @param nyear the number of years the investment is held
* @return the balance after nyear years
*/
ㄏノ Java そノ祘Α javadoc笆盢
瓃祘Α爹秆锣Θ呼Α ノ猭:
javadoc Futval.java
public static double futureValue(double initBalance,
double p, int nyear) {
if (nyear < 0) return 0;
if (p < 0) return 0;
double b = initBalance
* Math.pow(1 + p / (12 * 100), 12 * nyear);
return b;
}
ㄧ计 futureValue (return value) ㄤ戈Α double static ボ硂ㄧ计琌ノ摸よ猭(class method) public ボヴㄧ计常 ㄏノ硂ㄧ计
ㄒ肈:
Inside.java
(﹍絏)
代刚 Inside
b = futureValue(total/2, rate, year2 - year1);
把计跑计计瘤礛э
public static double futureValue(double initBalance,
double p, int nyear) {
p = 1 + p/12/100;
int n = 12 * nyear;
double b = initBalance * Math.pow(p, n);
return b;
}
琌硂ぃ琌 style
public static double futureValue(double initBalance,
double p, int nyear) {
double b = initBalance
* Math.pow(1 + p / (12 * 100), 12 * nyear);
System.out.println("The balance is now " + b);
return b;
}
ノ System.outΤ瓜ざ祘Α碞ぃㄏノ
printTime(now);
ㄒ肈: PrintTime.java (﹍絏)
public static void updateBalance(double balance, double by) {
double newBalance = balance * (1 + by / 100);
balance = newBalance;
}
public static void main(String[] args) {
double savings = 10000;
double rate = 6;
updateBalance(savings, rate);
...
}
main い savings ご礛ゼ跑 э
public static double updateBalance(double balance, double by) {
double newBalance = balance * (1 + by / 100);
return newBalance;
}
public static void main(String[] args) {
double savings = 10000;
double rate = 6;
savings = updateBalance(savings, rate);
...
}
ㄒ肈: Intname.java (﹍絏)