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??
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);
} }