In: Computer Science
Please do this in PSEUDOCODE.Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by the time that baby is ready for retirement (67 years)! Don’t believe us? Check out the compound interest calculator from MoneyChimp and plug in the numbers! To keep things simple, we’ll calculate interest in a simple way. You take the original amount (called the principle) and add back in a percentage rate of growth (called the interest rate) at the end of the year. For example, if we had $1,000 as our principle and had a 10% rate of growth, the next year we would have $1,100. The year after that, we would have $1,210 (or $1,100 plus 10% of $1,100). However, we usually add in additional money each year which, for simplicity, is included before calculating the interest. Your task is to design (pseudocode) and implement (source) for a program that 1) reads in the principle, additional annual money, years to grow, and interest rate from the user, and 2) print out how much money they have each year. Task 3: think about when you earn the most money! Lesson learned: whether it’s your code or your money, save early and save often… Sample run 1: Enter the principle: 2000 Enter the annual addition: 300 Enter the number of years to grow: 10 Enter the interest rate as a percentage: 10 Year 0: $2000 Year 1: $2530 Year 2: $3113 Year 3: $3754.3 Year 4: $4459.73 Year 5: $5235.7 Year 6: $6089.27 Year 7: $7028.2 Year 8: $8061.02 Year 9: $9197.12 Year 10: $10446.8
Step 1: Start
Step 2: Declare the variable principal (pr), annual addition (amt), rate of interest (rate), interest amount (intamount) of float type, no of years (years) and loop variable i of int type.
Step 3: Ask user to provide the required value and store in respective variables, initialize loop variable to 0
Step 4: if i<=years repeat step 5-8
Step 5: print the principal amount for current year with i value as year
Step 6: Add the annual addition tot the principal amount as pr=pr+amt
Step 7: calculate interest for the current year as intamount=(principal*rate*1)/100 i.e.year will be 1 for each case
Step 8: Add the interest amount to the principal amount to obtain new principal for next year as
principal=principal+intamount
Step 9: increment the value of i as i++
Step 10: Stop
Program:
//importing required class
import java.util.Scanner;
//class definition
public class SavingCalci {
//main method definition
public static void main(String[] args) {
//variable
declaration
double pr, amt, rate,
intamt;
int years=0, i=0;
Scanner input=new
Scanner(System.in);
//asking for user
input
System.out.print("Enter
the principal amount: $");
pr=input.nextDouble();
System.out.print("Enter
the yearly addition: $");
amt=input.nextDouble();
System.out.print("Enter
the no of years: ");
years=input.nextInt();
System.out.print("Enter
the rates (in %): ");
rate=input.nextDouble();
//running the loop
for(i=0;i<=years;i++){
//printing the details
System.out.println("Year "+i+": "+pr);
//incrementing the principle amount
pr=pr+amt;
intamt=(pr*rate*1)/100;
pr=pr+intamt;
}
}
}
Output: