In order to keep the amount of threads I post down. I have a new assignment that I'll just post here, unless that's against the rules? Anyway here it goes.
My assignment is to design a program that takes three user inputs. One for the amount invested, one for the amount of years of the investment, and then another for the amount of interest.
I've got this so far:
import javax.swing.JOptionPane; public class Investment { public static void main(String[] args) { double Total, investment, interest, intPerc; String stInvestment = JOptionPane.showInputDialog(null, "Enter the amount Invested: "); investment = Double.parseDouble(stInvestment); if (investment<=0) { JOptionPane.showMessageDialog(null, "You've entered an invalid amount for your Investment."); System.exit(-1); } String stYears = JOptionPane.showInputDialog(null, "Enter the amount of years of the Investment: "); int years = Integer.parseInt(stYears); if (years<=0) { JOptionPane.showMessageDialog(null, "You've entered an invalid amount for the amount of years of your Investment."); System.exit(-1); } String stInterest = JOptionPane.showInputDialog(null, "Enter the Percent of interest as a whole number: "); interest = Double.parseDouble(stInterest); while(years>0) { int time = years*12; intPerc = interest / 100; Total = ((investment * intPerc) + investment); System.out.println("You're investment after " + time + " months amounts to " + Total); years = years - 1; } } }
I have to problems, the main problem is that the output is incorrect, instead of applying the interest earned towards the new investment each time, it outputs the same amount each time.
This is an example of the output at 1000 at 2 years, with 3% interest.
You're investment after 24 months amounts to 1030.0
You're investment after 24 months amounts to 1030.0
Second problem isn't so much a problem as a question of interest. (Err, now looking at the code that I posted this doesn't have the keyboard.) but I have a second code that I'm working on using a scanner.)
At the first line I get a type of error saying that "Resource leak: 'keyboard' is never closed".
Just curious as to how to fix this. If you need the entire code I can post it, but in order to keep confusion down I only posted the bit that had the error.