// Investment.java
// Class Sample File for CBIS 4210
package retirementcalculator;

/** Investment models a simple monthly investment over time.
*/
public class Investment
{
	// fields
	/** Rate holds the current interest rate in percentage.
	*/
	private double rate;
	/** Years holds the number of years of investment.
	*/
	private int years;
	/** MonthlyAmt holds the amount of monthly deposit.
	*/
	private double monthlyAmt;
	/** Balance holds the current investment balance after the run().
	*/
	private double balance;

	// constructors
	/** Constructs a investment with default values (0%,$0).
	*/
	public Investment()
	{
		rate = 0;
		years = 0;
		monthlyAmt = 0;
	}

	/** Constructs an investment with the given values.
	@param aRate an annual interest rate in percent.
	@param anAmount a monthly amount to invest each month.
	@param aYears a number of years to invest.
	*/
	public Investment (double anAmount, double aRate, int aYears)
	{
          monthlyAmt= anAmount;
          rate = aRate;
          years = aYears;
	}

	// methods
	/** Run adds the monthly amount invested and computes interest monthly.
	*/
	public void run()
	{
		for (int i=0; i < (years * 12); i++)
			balance += (monthlyAmt + (balance*(rate/12/100)));
	}
	/** GetRate returns the annual interest rate in percent.
	@return the interest rate.
	*/
	public double getRate()
	{
		return rate;
	}
	/** GetYears returns the number of years of the investment.
	@return the number of years.
	*/
	public int getYears()
	{
		return years;
	}
	/** GetMonthlyAmt returns the monthly amount of deposit.
	@return the monthly amount of deposit.
	*/
	public double getMonthlyAmt()
	{
		return monthlyAmt;
	}
	/** Getbalance returns the total amount earned after run().
	@return the balance after the number of years.
	*/
	public double getBalance()
	{
		return ((int)(balance*100))/100.0;
	}

}

