Loan compare issue

Reply

Join Date: Sep 2009
Posts: 1
Reputation: ss_hat is an unknown quantity at this point 
Solved Threads: 0
ss_hat ss_hat is offline Offline
Newbie Poster

Loan compare issue

 
0
  #1
Sep 14th, 2009
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"

  1. import javax.swing.JOptionPane; //importing all of the joptionpane's
  2.  
  3. public class LoanCompare{
  4.  
  5. public static void main (String[ ] args)
  6.  
  7. {
  8.  
  9. boolean run = true;
  10.  
  11. while(run)
  12.  
  13. {
  14. 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
  15.  
  16. double loanAmt = Double.parseDouble(JOptionPane.showInputDialog("How much is the loan for? (eg. $15,000 put 15000)")); // how much the loan is for
  17.  
  18. double interestPercent = Double.parseDouble(JOptionPane.showInputDialog("What is the interest rate of the loan? (eg. 15% put 15)")); // percent of interest expected to pay
  19.  
  20. int increment = 0;
  21.  
  22. System.out.println("Payment # Principal Payment APR MR Interest Payment Principal Payment\n");//Prints the header
  23.  
  24. while(loanAmt>0)
  25. {
  26. double principalAmt = 0;// initialize pricipal
  27.  
  28. double monthlyIR = (interestPercent / 1200); // the monthly interest rate, a static amount
  29.  
  30. double interestPayment = ( loanAmt * monthlyIR); // amount paid towards the interest each month
  31.  
  32. double totalInterestPaid = interestPayment++; //calculation for total interest paid
  33.  
  34. double principalPayment = (loanAmt - interestPayment);// Principal payment column
  35.  
  36. System.out.printf("%5d %12.2f %9.2f %6.2f %5.2f %12.2f %17.2f\n", increment,principalAmt,monthlyPaymentAmt,interestPercent,monthlyIR,interestPayme
  37. nt,principalPayment);
  38.  
  39. loanAmt-=principalPayment; //loanAmt-=principal
  40.  
  41. increment++;
  42.  
  43. }
  44.  
  45. System.out.printf(" Total Interest Paid%9.2f\n\n", +totalInterestPaid); //Prints Total Interest Paid
  46.  
  47. }
  48. //need to figure out how to prompt user for another pass
  49. }
  50. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Loan compare issue

 
0
  #2
Sep 14th, 2009
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.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Reply

Tags
compare, java, loan

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC