When I try to run my program, it lets me enter in the beginning balance, interest rate, and number of months. However, when it hits the for loop, it completely skips over everything inside of it and prints out the amount that was entered for the starting balance. Can someone please help?

// Create decimal formatter for dollar amount
		DecimalFormat dollar = new DecimalFormat("###,###.00");

		// Get beginning balance
		input = JOptionPane.showInputDialog("Please enter starting account balance: ");

		// Create a BankAccount object
		BankAccount account = new BankAccount(input);

		// Check to make sure dollar amount account balance is valid amount

		// Get interest rate
		input = JOptionPane.showInputDialog("Please enter interest rate: ");

		// Get number of months
		input = JOptionPane.showInputDialog("Please enter number of months: ");

		for (int i= 1; i<= numMonths; i++)
		{	// Begin for loop
			input = JOptionPane.showInputDialog("Please enter deposited amount: " + i);

		    input = JOptionPane.showInputDialog("Please enter withdrawal amount: " + i);
        }	// End for loop

		// Display new balance
					"The current available balance is $ " +
6 Years
Discussion Span
Last Post by cale.macdonald

From what you posted, it looks like you are storing the input received from the JOptionPane in a variable called input, then overwrite it on the next call. As kramerd mentioned, if the value of numMonths (which in your posted code you do not assign) is 0 or less, the loop will not execute.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.