In: Computer Science
Bank Accounts in Java!
Design and implement a Java program that does the following:
1) reads in the principle
2) reads in additional money deposited each year (treat this as a constant)
3) reads in years to grow, and
4) reads in interest rate
And then finally prints out how much money they would have each year.
See below for formatting.
Enter the principle: XX
Enter the annual addition: XX
Enter the number of years to grow: XX
Enter the interest rate as a percentage: XX
Year 0: $XX
Year 1: $XX
Year 2: $XX
Year 3: $XX
Year 4: $XX
Year 5: $XX
Answer:
import java.io.*;
import java.util.Scanner;
class bank
{
public static void main(String[] args)
{
int principle,additinal_money,years,rate;
Scanner input = new Scanner(System.in);
System.out.println("Enter the principle: ");
principle = input.nextInt();
System.out.println("Enter the annual addition:
");
additinal_money = input.nextInt();
System.out.println("Enter the number of years to grow:
");
years = input.nextInt();
int [] new_amount = new int[years];
System.out.println("Enter the interest rate: ");
rate = input.nextInt();
for(int i=0;i<years;i++)
{
new_amount[i] =
principle*rate/100;
principle+= new_amount[i];
principle =
principle+additinal_money;
new_amount[i] = principle;
}
for( int i=0;i<years;i++)
{
System.out.println("year"+i+":
$"+new_amount[i]);
}
}
}