
import uk.co.jscieng.*;
public class interest extends SciGraph
{
	public static void main(String [] argv)
	{

		SciGraph.showText();
		SciGraph.print("Welcome to Alecia's Compound Interest Calculator. \n   \n");
		SciGraph.showText();
		SciGraph.print("Enter the principal, or the amount of money the account \n starts out with, in dollars:  ");
		String z = SciGraph.readln();
		double p = Double.parseDouble(z);
		
		SciGraph.showText();
		SciGraph.print("Enter the annual rate of the account in a percent (ex.- '.07'):   ");
		String k = SciGraph.readln();
		double r = Double.parseDouble(k);
		
		SciGraph.showText();
		SciGraph.print("Enter the duration in which the money stays in the account in years:  ");
		String g = SciGraph.readln();
		double t = Double.parseDouble(g);

		SciGraph.showText();
		SciGraph.print("Enter the number of times per year the interest is compounded:  ");
		String o = SciGraph.readln();
		double n = Double.parseDouble(o);
		
		SciGraph.showText();
		SciGraph.print("The balance is:  ");
		
		double a = p * Math.pow(1.0 + (r / n),n*t);
		a = Math.round(100.* a) /100.;
		SciGraph.print(a);
		SciGraph.print("  dollars");

		SciGraph.print("\n On the graph, the y-axis represents the balance, \n and the x-axis represents time in years \n \n");
		
		SciGraph.showGraph(-1, 25, -10, 6000);
		
		for (double tg = 0.0; tg < 6000; tg = tg + 1)
		{
			double ag = p * Math.pow(1.0 + (r / n),n*tg);
			SciGraph.line(tg,ag);
		}
		
		SciGraph.print("If the interest were compounded continuously, \n the balance would be:   ");
		double g3 = p * Math.pow(Math.E,r * t);
		g3 = Math.round(100. * g3) / 100.;
		SciGraph.print(g3);
		SciGraph.print("   dollars \n");
		
		SciGraph.print("The time it would take for your principal to double at this rate and \n compounding pattern would be approximately:  ");
		double dp = Math.log(2) / (n * Math.log(1 + (r/n)));
		dp = Math.round(100. * dp) / 100.;
		SciGraph.print(dp);
		SciGraph.print( "  years");
	}
		public void main()
		{
			main(new String[1]);
		}
}