📄 account.java
字号:
package ope.account;
/**
* The class <CODE>Account</CODE> represents accounts in
* a simple (unrealistic) banking system.
*/
public class Account {
private Customer owner; // fixed value
private double balance; // gatherer: sum of the deposits and withdrawals
/**
* Creates a new account of the given customer. The new
* account has a zero balance.
*
* @param owner the customer whose account is being created
*/
public Account(Customer owner) {
this.owner = owner;
this.balance = 0;
}
/**
* Returns the customer who owns the account.
*
* @return account owner
*/
public Customer getOwner() {
return this.owner;
}
/**
* Returns the current balance of the account.
*
* @return account balance
*/
public double getBalance() {
return this.balance;
}
/**
* Deposits the a given sum onto the account if the
* given value is positive. Otherwise, does nothing.
*
* @param amount the amount to deposit
*/
public void deposit(double amount) {
this.balance = this.balance + amount;
}
/**
* Tries to withdraw the given sum from the account if
* the given value is positive. Otherwise, does nothing.
* If the given value is higher than the account's current
* balance, only the money currently available on the
* account is withdrawn.
*
* @param amount the amount to withdraw
*/
public void withdraw(double amount) {
this.balance = this.balance - amount;
}
/**
* Transfers the given sum from this account to another given
* account, assuming that there is sufficient money available in
* this account. If not, no transfer is made at all.
*
* @param anotherAccount the accont the money is deposited on
* @param amount the amount to transfer
*/
public void transferTo(Account anotherAccount, double amount) {
this.withdraw(amount);
anotherAccount.deposit(amount);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -