All pastes #623331 Raw Edit

Untitled

public java v1 · immutable
·published 2007-07-17 14:40 UTC
rendered paste body
/**   A savings account that has a balance, and interest*/public class SavingsAccount2 {  private double balance;  private double interest;  /**     Constructs a bank account with a zero balance.  */  public SavingsAccount2() {    this.balance = 0;    this.interest = 3; //default 3% interest rate (i dont know)  }  /**     Constructs a bank account with a nonzero balance.     @param initialBalance the initial balance     @param interestRate the interest rate  */  public SavingsAccount2(double initialBalance, double interestRate) {    this.balance = initialBalance;    this.interest = interestRate;  }  /**     Deposits a given amount into the savings account     @param amount the amount to deposit  */  public void deposit(double amount) {    this.balance = this.balance + amount;  }  /**     Withdraws a given amount from the savings account     @param amount the amount to withdraw  */  public void withdraw(double amount) {    this.balance = this.balance - amount;  }  /**     Gets the current balance of the bank account     @return the current balance  */  public double getBalance() {    return this.balance;  }  /**     Applies the given interest rate to the account.  */  public void applyInterest() {    double decimalInterest = interest / 100;    if (this.balance > 0) {      this.balance = this.balance + (decimalInterest * this.balance);    }  }}