I'm running into a roadblock on my program and the deadline is Tuesday(9/14). I'm at work all day and I'm hoping the interwebs can help me while I'm away (i can check @ lunch). I'm very new to Java and I'm still trying to digest the terminology so any clear explanations are greatly appreciated.

The Questions/Problem:

1. I would like to know how to ask the user to compare another loan. (I'm guessing/hoping it's just one more line of code)

2. How to redisplay the totals from each loan entered as noted at the below of the post: (the program needs to compare all the loans entered, these are the comparisons)

The totals needed are;

  1. how many months it took to pay off the loan
  2. original principal
  3. payment amount
  4. Interest Rate
  5. Total Interest Paid

3. The current code is giving me the error "cannot find symbol variable totalInterestPaid on line 46"

import javax.swing.JOptionPane; //importing all of the joptionpane's

public class LoanCompare{

public static void main (String[ ] args)

{

boolean run = true;

while(run)

{
    double monthlyPaymentAmt= Double.parseDouble(JOptionPane.showInputDialog("How much can you pay per month?(eg. $250 put 250)")); // how much the user can afford to pay per month
       
       double loanAmt = Double.parseDouble(JOptionPane.showInputDialog("How much is the loan for? (eg. $15,000 put 15000)")); // how much the loan is for
       
       double interestPercent = Double.parseDouble(JOptionPane.showInputDialog("What is the interest rate of the loan? (eg. 15% put 15)"));         // percent of interest expected to pay
         
    int increment = 0;
   
    System.out.println("Payment # Principal Payment APR   MR     Interest Payment Principal Payment\n");//Prints the header
   
        while(loanAmt>0)
{
    double principalAmt = 0;// initialize pricipal
   
    double monthlyIR = (interestPercent / 1200); // the monthly interest rate, a static amount
   
    double interestPayment = ( loanAmt * monthlyIR);  // amount paid towards the interest each month

    double totalInterestPaid = interestPayment++; //calculation for total interest paid

    double principalPayment = (loanAmt - interestPayment);// Principal payment column
   
     System.out.printf("%5d %12.2f %9.2f %6.2f %5.2f %12.2f %17.2f\n",  increment,principalAmt,monthlyPaymentAmt,interestPercent,monthlyIR,interestPayme
nt,principalPayment);

    loanAmt-=principalPayment; //loanAmt-=principal
   
    increment++;
   
}

System.out.printf("                          Total Interest Paid%9.2f\n\n", +totalInterestPaid); //Prints Total Interest Paid

}
//need to figure out how to prompt user for another pass
}
}

The reason why you are getting the error on "totalInterestPaid" is cause you have declared it inside the while block, due to which it is not visible to any code outside that block and hence you are getting that error.
Move the declaration of the variable to outside the "while" block and the compiler should not complain any longer.

As far as comparing values from different loans is concerned, you will need to use arrays to store the values of the previous loan amounts, to make it possible for them to be compared later, as of now once you have calculated and displayed the values on line 36 above, you overwrite them with the values of the next loan amount.

The government is taking loan issues seriously.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.