Results 1 to 3 of 3
  1. #1
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default Norm!! I got the loop to work!

    SO i got the loop to work... sort of. The code compiles, ask the user to enter a loan, but if no is clicked it still goes on with the program, also once at the end of the program, it does not loop back to the beginning, but the everything compiles. Now that i have cleaned it up a bit do you think you can figure out whats going on??

    Java Code:
    import javax.swing.*;
    
    
    
    public class MortgageApp3 {
    	public static void  main(String args[])
    		{
    
    
    
    
    
    
    
    		double loan,
    		 interest_yr,
    		 years,
    		 interest_mo,
    		 loan_pmts,
    		 payments,
    		 new_balance,
    		 interest,
    		 interestamt,
    		 principal,
    		 principalamt,
    		 payamt,
    		 balance,cont;
            
             int p;
    
            //Above is all the varaibles used for calculations
    
    
    
            String loanamt,
    		  interest_peryr,
    	      yearstot,
    	      pay_amt,
    	      restart;
    	    //The above declares the strings for the program
    
    
    
               cont = JOptionPane.showConfirmDialog(null, "Want to enter a loan?", "Loan Calcuator",
               JOptionPane.YES_NO_OPTION);
    
    
    
    
    
    
    
    	 loanamt= JOptionPane.showInputDialog("Enter Loan Amount");    //Obtains input from user for loan amount
    	 interest_peryr=JOptionPane.showInputDialog("Enter the Interest Percentage: Example 5.6");  //Obtains input from user for interest %
    	 yearstot=JOptionPane.showInputDialog("Enter Loan Period in Years");  //Obtains input for length of loan
    
    
    
    
         // Below is the code to parse stings into doubles
    	 loan=Double.parseDouble(loanamt);
    	 interest_yr=Double.parseDouble(interest_peryr);
    	 years=Double.parseDouble(yearstot);
    
    
    
    
         interest_mo = (interest_yr/12.0)/100.0; // Turns percent whole numbers into decimals
         loan_pmts= years * 12;  //Gets total amount of months the loan will last after user inputs length of loan in years
         payments = (loan*interest_mo/(1- Math.pow((1+interest_mo),-loan_pmts))); //Loan calculation
         
         JOptionPane.showMessageDialog (null, String.format( "Your payment is: $ %.2f ", + payments)); //Shows payment with 2 decimal places
    
    
         principalamt= payments - (loan *interest_mo);  //calculates principle
    
         JOptionPane.showMessageDialog(null, String.format( "your prinicple paid is: $ %.2f ", + principalamt)); //shows principle with 2 decimal places
    
         interestamt= payments-principalamt ;  //calculates interest
    
         JOptionPane.showMessageDialog(null, String.format( "your interest paid is: $ %.2f ", + interestamt)); //shows interest with 2 decimal places
    
    
    
    
    
    
    //below is the loop
       p=1;
      balance=loan;
    
    
    
      for(int month=0;month<(years*12);month++)
    
    
    
      {
      	interest=balance*interest_mo;
      //System.out.println("interest "+interest);
    
      principal=payments-interest;
      //System.out.println("principal "+ principal);
    
      System.out.println("For Payment: " +p++ );
      System.out.println( String.format("Principal paid is: $ %.2f",  + principal));
    
      balance=balance-principal;
      System.out.println( String.format("Remaining balance is: $ %.2f",
        + balance));
    
    
    
     }
    
    while(cont==JOptionPane.YES_OPTION)continue;
    
    if(cont==JOptionPane.NO_OPTION);System.exit(0);
    
    
    
    
    		}        }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Now it's time you learn how to format your code for readability.
    Code Conventions for the Java(TM) Programming Language: Contents

    And get rid of unnecessary blank lines.

    db

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,562
    Rep Power
    23

    Default

    figure out whats going on
    Why? Does the program execute and produce the desired results? If not post the output and explain what is wrong with it.

Similar Threads

  1. Need help with getting second loop to work
    By twcast in forum New To Java
    Replies: 3
    Last Post: 02-08-2010, 02:15 PM
  2. do-while loop doest work here? help me
    By dhanh90 in forum New To Java
    Replies: 4
    Last Post: 10-18-2009, 02:57 AM
  3. Why won't this while loop work?
    By trueblue in forum New To Java
    Replies: 6
    Last Post: 05-23-2009, 08:10 PM
  4. What happened to Norm
    By Fubarable in forum Forum Lobby
    Replies: 2
    Last Post: 04-30-2009, 04:26 AM
  5. my loop doesn't work.. pls help???
    By ashton in forum New To Java
    Replies: 5
    Last Post: 01-16-2009, 08:24 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
  •