I. Iif interest is compounded annually, it grows as follows. Suppose P0 is the i
ID: 3544871 • Letter: I
Question
I. Iif interest is compounded annually, it grows as follows. Suppose P0 is the initial amount and INT is the interest rate per year. If P1, P2, and P3 represent the balance at the end of the first, second, and third year, respectively then:
P1 = P0 + P0 * INT = P0 * (1 + INT)
P2 = P1 + P1 + INT = P1 * (1 + INT) = P0 * (1 + INT) * (1 + INT)
= P0 * (1 + INT)2
P3 = P2 + P2 * INT = P2 * (1 + INT)
= P0 * (1 + INT) * (1 + INT) * (1 + INT)
= P0 * (1 + INT)3
and so on
Explanation / Answer
//Please rate my answer after running and reading the clarity of code
import java.util.Scanner;
class ira
{
int p0;
int i;
float temp=1,interest,aftr_60,aftr_61,incm_pm;
public void input()
{
System.out.print(" Welcome to IRA Enter initial investment: ");
Scanner input = new Scanner(System.in);
p0 = input.nextInt();
System.out.print("Enter interest rate in percent: ");
interest = input.nextFloat();
interest = interest/100;
}
void calculate()
{
for(i=0; i<(60-16); i++)
temp = temp*(1+interest);
aftr_60 = p0*temp;
aftr_61 = p0*temp*(1+interest);
temp = (aftr_61*interest);
incm_pm = temp / 12;
}
void display()
{
System.out.print(" The initial investment was $"+p0+". The total amount accumulated after "+(60-16)+" years, if $"+p0+" is allowed to compound with an interest rate of "+interest*100+"%, comes to $"+aftr_60+".The total amount accumulated after "+(60-16 + 1)+" years, if $"+p0+" is allowed to compound with interest rate of 10%, comes to $"+aftr_61+".The interest earned during this year is $"+temp+". If interest is withdrawn each year thereafter, my income is $"+incm_pm+" per month. ");
}
public static void main(String args[])
{
ira a = new ira();
a.input();
a.calculate();
a.display();
}
}