Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. String InputInvestmentAmount = JOptionPane.showInputDialog(null, "Hello, and welcome to Compound Investing.nThis programme will print out a titled table, that will show you nthe amount of yearly investment, for a period up to 15 years."
  2. + "nPlease enter a Yearly Investment Amount ($) below.","Compound Investing Calculator",JOptionPane.INFORMATION_MESSAGE);
  3. String InputInterest = JOptionPane.showInputDialog(null, "Please input the interest rate in percent (%) below.","Compound Investing Calculator",JOptionPane.INFORMATION_MESSAGE);
  4. String InputYearsInvested = JOptionPane.showInputDialog(null, "Lastly, please enter the number of years for the investment. "
  5. + "No numbers higher than 15, please.","Compound Investing Calculator", JOptionPane.INFORMATION_MESSAGE);
  6. double investmentAmount; //the amount the user chooses to invest, expressed as a double
  7. investmentAmount = Double.parseDouble(InputInvestmentAmount);
  8. double Interest; // amount of interest in percent, expressed as a double
  9. Interest = Double.parseDouble(InputInterest);
  10. double YearsInvested; //the total years (under 15) the user wants to invest, expressed as a double
  11. YearsInvested = Double.parseDouble(InputYearsInvested);
  12. double Zero = 0; //a starting point for the year
  13. double Total;
  14. System.out.println("Years Invested ttAmount in AccountttInterestttTotal");
  15. if (YearsInvested >=16)
  16. {
  17. JOptionPane.showMessageDialog(null,"I am sorry. Please make sure that you are investing your money for "
  18. + "less than 16 years.", "Compound Investing Calculator",JOptionPane.ERROR_MESSAGE);
  19. }
  20. do {
  21. Zero++; //the year
  22.  
  23. Interest = (investmentAmount*=(Interest/100));
  24. Total = investmentAmount+Interest;
  25. System.out.format("%5.2f%32f%28f%25f%n",Zero,investmentAmount,Interest,Total);
  26.  
  27. }
  28. while (YearsInvested <= 15 && Zero<=YearsInvested-1);
  29.  
  30. Years Invested Amount in Account Interest Total
  31. 1.00 12.000000 4.000000 12.000000
  32. 2.00 1.440000 0.480000 1.440000
  33. 3.00 0.020736 0.006912 0.020736
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement