/** * 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; }