Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class IRAInterestCalculator {
- public static void main(String[] args){
- double interestRate;
- double accountValue = 0;
- double yearlyDeposit;
- int years;
- int ycounter;
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter the yearly deposit into the account: ");
- yearlyDeposit = scan.nextDouble();
- System.out.print("Enter the yearly interest rate of the account as a percent: ");
- interestRate = (scan.nextDouble() / 100) + 1;
- System.out.print("Enter the number of years to which to calculate: ");
- years = scan.nextInt();
- System.out.println("====================================");
- for(ycounter=1;ycounter<=years;ycounter++){
- accountValue += yearlyDeposit;
- accountValue *= interestRate;
- System.out.println("Year " + ycounter + ": \t $" + accountValue);
- }
- System.out.println("====================================");
- System.out.println("After " + years + " years, you have earned $" + accountValue + ". You're rich!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement