Java Reference
In-Depth Information
// Defines a customer account
public class Account {
// Constructor
public Account(int accountNumber, int balance) {
this.accountNumber = accountNumber;
// Set the account
number
this.balance = balance;
// Set the initial
balance
}
// Return the current balance
public int getBalance() {
return balance;
}
// Set the current balance
public void setBalance(int balance) {
this.balance = balance;
}
public int getAccountNumber() {
return accountNumber;
}
@Override
public String toString() {
return "A/C No. " + accountNumber + " : $" + balance;
}
private int balance;
// The current
account balance
private int accountNumber;
// Identifies this
account
}
Directory "BankOperation 1"
How It Works
The Account class is also very simple. It just maintains a record of the amount in the account as a balance
and provides methods for retrieving and setting the current balance. Operations on the account are per-
formed externally by the Bank object. You have a bit more than you need in the Account class at the
moment, but the methods you don't use in the current example might be useful later.
Search WWH ::




Custom Search