(Finance: retirement plans) Use loops instead of financial equation for this pro
ID: 3565951 • Letter: #
Question
(Finance: retirement plans) Use loops instead of financial equation for this program. There are two pans of the question. Both are similar with different numbers. Write only one program for both situations. Use interest rate 6.1% in computation. Use at least two different loop statements in your program. Always round your amount to penny. 1. A TV commercial says that putting $45 a month for retirement, after 30 years. there will be millions in your saving. Calculate the actual retirement saving for this plan. 2. A traditional retirement plan withholds 8% salary for retirement. For someone begins with annual salary $ 20000. what the retirement saving after 30 years will be? Assume that this person gets 3% salary increase every year because of job promotion and salary raise. Notes: The interest rate is annual. Our computation is monthly. Similarly, the salary is annual and the deposit is monthly. Consider the first deposit for retirement as time 0. For example. the first deposit (at time 0) is $50. At end of month one, it becomes $50.25. Additional deposit ($50) will be added at the beginning of month two. At the end of month two, there will be $100.75. The process goes on and on till end of 30 years. Here is a sample run based on different data: Retirement saving of case 1 is 613538.01 Retirement saving of case 2 is 424330.88Explanation / Answer
Program:
//program FinanceDemo
import java.text.*;//to use the DecimalFormat Class
class FinanceDemo
{
static double RATE=0.005;
public static void main(String []a)
{
//DecimalFormat class of java.text.* package
//used to set the decimal value to two places
DecimalFormat df = new DecimalFormat("####0.00");
//amount_month of case1
double amount_month=45;
int year=30;
//convert years to months
int months=year*12;
System.out.println("years: "+months);
//call and display the retirement savings for Case1
System.out.println("Retirement savings for Case 1: "+ df.format(savingsloop(months, amount_month)*100));
//call and display the retirement savings for Case1
System.out.println("Retirement savings for Case 2: "+ df.format(savingsloop2(months)*100));
}
//savingsloop method for Case1
public static double savingsloop(int months, double amount)
{
int month = 1;
double savings = 0;
//condition to calculate till month=360
while( month <= months)
{
//deposit with savings
savings+= amount ;
//savings is summed up with rate
savings = savings+( savings * RATE);
//increment the month
month = month + 1;
}
return savings;
}
//savingsloop2 is calculated for per month
public static double savingsloop2(int months)
{
//monthly salary of an employee
double salary_month=1666.66;
//monthly deposit of 8% of salary
double deposit=salary_month*0.08;
int month = 1;
int i=1;
double savings = 0;
//condition to calculate till month=360
while( month <= months)
{
//condition to check whether the month
//completes a year
if(month==12*i)
{
//salary increments to 3%
//therefore, monthly salary also
//increments to 3%
double temp=deposit*0.03;
deposit=deposit+temp;
i++;
}
//deposit with savings
savings+= deposit ;
//savings is summed up with rate
savings = savings+( savings * RATE);
//increment the month
month = month + 1;
}
return savings;
}
}
-----------------------------------------------------------------------------------------------------
Sample Code:
years: 360
Retirement savings for Case 1: 4542919.28
Retirement savings for Case 2: 18806086.62
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.