⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bankaccount.java

📁 ssd3的教程 是我们老师给我们的 纯英文 有兴趣的可以
💻 JAVA
字号:
/**
 * This class models a bank account.
 *
 * @author author name
 * @version 1.0.0
 */
public class BankAccount {

    /* Balance of the account*/
    private double balance;

    /**
     * Creates a new <code>BankAccount</code> object with an
     * initial balance of zero.
     */
    public BankAccount() {

        balance = 0.0;
    }

    /**
     * Returns the balance of this account.
     *
     * @return the balance of this account
     */
    public double getBalance() {

        return balance;
    }

    /**
     * Deposits money in this account. If the specified amount is
     * positive, the account balance is updated.
     *
     * @param amount amount of money to add to the balance.
     * @return <code>true</code> if the money is deposited;
     *         <code>false</code> otherwise.
     */
    public boolean deposit(double amount) {

        if (amount > 0) {
            balance += amount;

            return true;
        } else {

            return false;
        }
    }

    /**
     * Withdraws money from this account. If the specified amount is
     * positive and the account has sufficient funds, the
     * account balance is updated.
     *
     * @param amount  amount of money to subtract from the balance.
     * @return <code>true</code> if the money is withdrawn;
     *         <code>false</code> otherwise.
     */
    public boolean withdraw(double amount) {

        if (amount > 0 && balance >= amount) {
            balance -= amount;

            return true;
        } else {

            return false;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -