package hw02;

public class Account {

	/**
	 * Account class to represent a bank account
	 * Model an account with two fields:
	 * 	- Balance - the amount of money in the account
	 *  - Interest - the percent interest earned in one year
	 */

	private Money balance;
	private double interest;

	/**
	 * Create a new account
	 * @param balance
	 * @param interest
	 */
	public Account(Money balance, double interest) {
		this.balance = balance;
		this.interest = interest;
	}

	/**
	 * deposit more money into the account
	 * @param depositAmount
	 */
	public void deposit(Money depositAmount) {
		// add the depositAmount to the balance, and save the
		// result in the balance field
		balance=balance.add(depositAmount);
	}

	/**
	 * Assuming a year has passed, add the annual interest to the account
	 */
	public void addInterest() {
		balance=balance.mult(1.0+interest);
	}

	/**
	 * withdraw money from the account
	 * 		Note that if there is not enough money in the account
	 * 		to make the requested withdrawal, the bank will deny the
	 * 		withdrawal request and tell the user that he does not have
	 * 		enough money to withdraw that amount ("Insufficient funds")
	 * @param withdrawAmount
	 */
	public void withdraw(Money withdrawAmount) {
		// check to make sure there is enough money in the balance
		// 	of this account to make the requested withdrawal.
		// If there is not enough, do not change the balance, but
		// 	print the following message: "Insufficient funds";
		//	If there is enough, subtract that amount from the balance.
		if (balance.compareTo(withdrawAmount) < 0) {
			System.out.println("Insufficient funds");
			return;
		}
		balance=balance.add(withdrawAmount.mult(-1));
	}

	/**
	 * get the current balance in the account
	 * @return the balance
	 */
	public Money getBalance() {
		return balance;
	}

	/**
	 * get the current interest rate on this account
	 * @return the interest
	 */
	public double getInterest() {
		return interest;
	}

	public String toString() {
			return "Account balance=" + balance + " interest=" + interest;
	}
	
	public static void main(String[] args) {
		Account checking = new Account(new Money(500.0),0.03);
		System.out.println("Checking account: " + checking);
		checking.withdraw(new Money(39.48));
		System.out.println("After paying electric $39.48: " + checking);
		checking.deposit(new Money(283.75));
		System.out.println("After depositing paycheck $283.75: " + checking);
		checking.addInterest();
		System.out.println("After adding interest: " + checking);
	}
		
}