All pastes #1593575 Raw Edit

SavingsAccount

public java v1 · immutable
#1593575 ·published 2009-10-05 02:33 UTC
rendered paste body
/** * A class that creates a savings account. */public class SavingsAccount{    /**     * Constructs a savings account with an initial balance an interest rate.     * @param initialBalance The initial amount in the account.     * @param interest The percentage of interest.     */    public SavingsAccount(double initialBalance, int interest)    {        balance = initialBalance;        interest_rate = interest;    }    /**     * Deposits a given amount of money into the account.     * @param amount The amount to deposit.     */    public void deposit(double amount)    {        double newBalance = balance + amount;        balance = newBalance;    }    /**     * Withdraws a given amount of money from an account.     * @param amount The amount to withdraw.     */    public void withdraw(double amount)    {        double newBalance = balance - amount;        balance = newBalance;    }    /**     * Gets the current balance of the account.     */    public double getBalance()        {            return balance;        }        /**         * Calculates interest and adds it to the account.         */        public void addInterest()        {            newBalance = balance*(interest_rate/100) + balance;            balance = newBalance;        }   private double newBalance;private double balance;private double interest_rate;}