?? ex040204.java
字號:
class SavingsAccount{
static double annualInterestRate;
private double savingsBalance;
SavingsAccount(double Balance){
savingsBalance=Balance;
}
void calculateInterest(int n){
for (int i=1;i<=n;i++){
savingsBalance+=savingsBalance*SavingsAccount.annualInterestRate;
}
}
double getSavingBalance()
{
return savingsBalance;
}
static void modifyInterestRate(double rate){
annualInterestRate=rate;
}
}
public class Ex040204{
public static void main(String[] args){
SavingsAccount saver1=new SavingsAccount(2000.00);
SavingsAccount saver2=new SavingsAccount(3000.00);
SavingsAccount.modifyInterestRate(0.04);
saver1.calculateInterest(8);
saver2.calculateInterest(8);
System.out.println("儲戶1 8年的儲蓄額:"+saver1.getSavingBalance());
System.out.println("儲戶2 8年的儲蓄額:"+saver2.getSavingBalance());
SavingsAccount.modifyInterestRate(0.05);
saver1.calculateInterest(2);
saver2.calculateInterest(2);
System.out.println("儲戶1 2年的儲蓄額:"+saver1.getSavingBalance());
System.out.println("儲戶2 2年的儲蓄額:"+saver2.getSavingBalance());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -