Results 1 to 3 of 3

Thread: While Loop

  1. #1
    lala is offline Member
    Join Date
    Oct 2010
    Rep Power

    Default While Loop

    I am tryng to write a program that will calculate:
    interest, and monthly payment.

    The program should output the number of months it wold take to repay the loan. I've got dialog boxes to input the values, but they are not in the while loop. (??) More confused.

    Principle is 1000
    Monthly payment is $25
    interest rate per month is 7.2/12=.6%

    My program is in a loop
    My mind is in aloop. I have thoroughly confused myself.
    Please help. Please turn me around. :confused:

    Java Code:
    import java.util.*;
    import javax.swing.JOptionPane;  
    public class MonthlyPmts {
    public static void main(String[] args){
    	/* Declaring the variables that will be used in the problem */
    		String loanAmt;
    		String intPerYr;
    		String monthlyPmt;
    		double interest;
    		double principal = 1000;
    		double intRateMon = .06;
    		double monPay = 25;		
    	while (principal <= 1000)
    	/* Perform the calculations  */ 	
    interest = (principal * intRateMon);
    monPmt = (principal - interest - monPay); 
    	/* Input Dialog boxes                           */
    		loanAmt = JOptionPane.showInputDialog
    					 ("Enter the loan amount: ");	
    		intPerYr = JOptionPane.showInputDialog
    					 ("Enter the interest rate per year: ");
    		monthlyPmt = JOptionPane.showInputDialog
    					 ("Enter the monthly payment: ");

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Rep Power


    Your program never gets as far as the dialog boxes. It hits the while loop and gets stuck because principal never goes above 1000.

    Even if it did get out of the loop, the variables loanAmt, intPerYr and monthlyPmt aren't used anywhere.

  3. #3
    lala is offline Member
    Join Date
    Oct 2010
    Rep Power

    Default While Loop

    Thanks for responding. How do I incorporate my dialog boxes in the loop w/my calculation routine?

Similar Threads

  1. Loop Help Please
    By JavaAssistance in forum New To Java
    Replies: 11
    Last Post: 09-26-2010, 10:05 PM
  2. Replies: 5
    Last Post: 04-30-2010, 05:05 PM
  3. using for loop...pls help
    By in forum Eclipse
    Replies: 2
    Last Post: 12-13-2009, 09:30 AM
  4. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 08:46 PM
  5. while loop
    By Unknown1369 in forum New To Java
    Replies: 5
    Last Post: 07-08-2008, 10:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts