檔案:DemandDepositAccount.java
package bank; public class DemandDepositAccount { int balance; DemandDepositAccount(int deposit){ balance = deposit; } public void deposit(int money) { balance += money; } public void withdraw(int money){ balance -= money; } public int inquiry() { return balance; } }
檔案:AccountText.java
package bank; public class AccountTest { public static void main(String[] args) { DemandDepositAccount demandDepositAcc = new DemandDepositAccount(1000); demandDepositAcc.deposit(500); demandDepositAcc.withdraw(300); System.out.println("活期賬戶餘額:" + demandDepositAcc.inquiry()); } }執行結果
沒有留言:
張貼留言