/*
	BankAccount.java
	
	Part B of Assignment 3.
*/

public class BankAccount {

  // State variables
  private long balance = 0;  // recorded in pennies.

  private String name = "No Name!";
  
  private double interestRate = 0;

// Constructors
  private BankAccount() {
    // If you make the default constructor private, you disallow anyone from
    // making an account w/o the proper information.
  }
  
  /** Creates a BankAccount.
  	  @param initialBalance The starting balance of the account.
  	  @param aName The name of the account owner.
  	  @param interest The interest rate.
  */
  public BankAccount( double initialBalance, String aName, double interest) {
    if( initialBalance > 0)
      balance = (long)(initialBalance * 100);
    name = aName;
    if( interest > 0)
      interestRate = interest / 100;
  }

// Getters
  /** Gets the current balance of the account in dollars.
  */
  public double getBalance() { return( balance / 100.0);}
  /** Gets the name of the account owner.
  */
  public String getName() { return( name);}
  /** Gets the interest rate earned by the account.
  */
  public double getInterestRate() { return( interestRate);}
  
// Other functions
  /** Deposits money in the account.
  	  @param money The amount of money to deposit.
  */
  public void credit( double money) {
    balance += money * 100;
  }
  /** Withdraws money from the account.
  	  @param money The amount of money to withdraw.
  */
  public void debit( double money) {
    if( (money * 100) > balance) {
      System.out.println(" You can't take out that much moolah");
    }
    else {
      balance -= money * 100;
    }
  }
  /** Adds a month's worth of interest to the account.
  */
  public void monthlyUpdate() {
    balance *= 1.00 + ( interestRate / 12);
  }
  
  /** Returns a string representation of the account.
  */
  public String toString() {
    String s = "The balance of " + name + "'s account is $ " + (balance /100);
    s += "." + (balance % 100) + ".";
    return( s);
  }
}
