/*
	BankAccount.java
	
*/

public class BankAccount {

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

  private String name = "No Name!";
  
  private String password = "password";
  
  private double interestRate = 0; // Note that 5% is recorded as 0.05 internally!!

// 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 aName The name of the account owner.
  	  @param aPassword The initial password for this account.
  	  @param initialBalance The starting balance of the account.
  	  @param interest The interest rate in percent.
  */
  public BankAccount( String aName, String aPassword, double initialBalance,  double interest) {
    if( initialBalance > 0)
      balance = (long)(initialBalance * 100);
    name = aName;
    password = aPassword;
    if( interest > 0)
      interestRate = interest / 100;
  }

// Getters and setters
  /** 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);}
  /** Gets the password for this account
  */
  public String getPassword() { return( password);}
  /** Sets the password for this account
  */
  public void setPassword( String aNewPassword) { password = aNewPassword;}
  
// 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 double monthlyUpdate() {
  	double interestPaid = balance * ( interestRate / 12);
    balance += interestPaid;
    return( interestPaid / 100);
  }
  
  /** 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);
  }
}
