943,898 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2503
  • Java RSS
Sep 14th, 2009
0

Loan compare issue

Expand Post »
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"

Java Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ss_hat is offline Offline
1 posts
since Sep 2009
Sep 14th, 2009
0

Re: Loan compare issue

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.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Sep 4th, 2010
0
Re: Loan compare issue
The government is taking loan issues seriously.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
James cuck is offline Offline
7 posts
since Jun 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Array sorting help
Next Thread in Java Forum Timeline: Java tooltips have no text when overlapping bounds





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC