Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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."
- + "nPlease enter a Yearly Investment Amount ($) below.","Compound Investing Calculator",JOptionPane.INFORMATION_MESSAGE);
- String InputInterest = JOptionPane.showInputDialog(null, "Please input the interest rate in percent (%) below.","Compound Investing Calculator",JOptionPane.INFORMATION_MESSAGE);
- String InputYearsInvested = JOptionPane.showInputDialog(null, "Lastly, please enter the number of years for the investment. "
- + "No numbers higher than 15, please.","Compound Investing Calculator", JOptionPane.INFORMATION_MESSAGE);
- double investmentAmount; //the amount the user chooses to invest, expressed as a double
- investmentAmount = Double.parseDouble(InputInvestmentAmount);
- double Interest; // amount of interest in percent, expressed as a double
- Interest = Double.parseDouble(InputInterest);
- double YearsInvested; //the total years (under 15) the user wants to invest, expressed as a double
- YearsInvested = Double.parseDouble(InputYearsInvested);
- double Zero = 0; //a starting point for the year
- double Total;
- System.out.println("Years Invested ttAmount in AccountttInterestttTotal");
- if (YearsInvested >=16)
- {
- JOptionPane.showMessageDialog(null,"I am sorry. Please make sure that you are investing your money for "
- + "less than 16 years.", "Compound Investing Calculator",JOptionPane.ERROR_MESSAGE);
- }
- do {
- Zero++; //the year
- Interest = (investmentAmount*=(Interest/100));
- Total = investmentAmount+Interest;
- System.out.format("%5.2f%32f%28f%25f%n",Zero,investmentAmount,Interest,Total);
- }
- while (YearsInvested <= 15 && Zero<=YearsInvested-1);
- Years Invested Amount in Account Interest Total
- 1.00 12.000000 4.000000 12.000000
- 2.00 1.440000 0.480000 1.440000
- 3.00 0.020736 0.006912 0.020736
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement