| | |
Loan compare issue
![]() |
•
•
Join Date: Sep 2009
Posts: 1
Reputation:
Solved Threads: 0
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;
3. The current code is giving me the error "cannot find symbol variable totalInterestPaid on line 46"
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;
- how many months it took to pay off the loan
- original principal
- payment amount
- Interest Rate
- 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)
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.
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 ?"
"How to ask questions the smart way ?"
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: GridBagLayout: String not printing as expected
- Next Thread: How do i recode a Phone???
| Thread Tools | Search this Thread |
.net ajax android apple applet application appportability array automation bidirectional binary bluetooth bold build buyouts c++ class code codesnippet color compare compiler component convert coordinates deploy derby design desktop development developmenthelp dice ebook eclipse error ext firefox fractal game glassfish google gui guidancer gxt helpwithhomework html hyper image int integer java javafx javascript jetbrains jni julia keyword klocwork linux loan mac machine main method microsoft mysql netbeans newbie officefileformats oracle panel plazmic poi printf problem programming property python random recursion reporting researchinmotion ruby service set software sort sql sun superclass support swing threads transfer tree ubuntu virtualization web webservices windows







