?? testaccountclass.java
字號:
public class TestAccountClass {
public static void main (String[] args){
Account money = new Account(1122,20000,0.045);
money.withdraw(2500);
money.deposit(3000);
System.out.println("The balance is "+money.getBalance());
System.out.println("The monthly interest is "+money.getMonthlyInterestRate());
}
}
class Account {
private int id;
private double balance;
private double annualInterestRate;
Account (){
}
Account(int newId , double newBalance , double newAnnualInterestRate){
id = newId;
balance = newBalance;
annualInterestRate = newAnnualInterestRate;
}
/**return the id of the account */
public int getId(){
return id;
}
/** return the balance of the account */
public double getBalance(){
return balance;
}
/** return the interest rate of the account */
public double getAnnualInterestRate(){
return annualInterestRate;
}
/** set a new id */
public void setId ( int newId){
id = newId;
}
/** set a new balance */
public void setBalance (double newBalance){
balance = newBalance;
}
/** set a new interest rate */
public void setInterestRate (double newInterestRate){
annualInterestRate = newInterestRate;
}
public double getMonthlyInterestRate(){
double monthlyInterestRate = annualInterestRate / 1200;
return monthlyInterestRate;
}
public void withdraw(double amount){
balance -= amount;
}
public void deposit ( double amount){
balance += amount;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -