Need Help With Java: Reading a Text File to Pull Data From it.?

My program is to create a mortgage calculator. The user is required to enter the loan principal then selects from 3 separate loans in a combo box. Once they are done, they click calculate.

In my actionPerformed method I have something along the lines of:
If (source == calculate) \ calculate is the button
{
if (selection == 0) \meaning this is loan type one from the combo box
{ \ calculate loan one’s method
}
else if (selection == 1) \ selection for loan 2 from the combobox
{ \ calc loan 2’s method
}
else if (selection == 2) \ selection for loan 3 from the combobox
{ \calc loan 3’s method
}
etc.

Here’s my dilemma. I need to be able to create a text file (done) and somehow have my program read the interest rates from that file to use for each loan’s calculations. But I keep confusing myself on how to do this because I am still not quite understanding it.

I have read lots of help documents on java, and everything talks about the different components of the method to read the file, but I have yet to find something that explains how to create the method and how to tell my program to “take line 0 and use that for loan 1’s interest rate. Take line 1 for 2’s, take line 2 for 3’s”

So, any help would be realllly appreciated.

P.S. Please don’t tell me to go to the Java help forums….been there done that.
Also, I am not necessarily looking for answers. Good references or resources on how to do it would be great too.
Thank you very very very much Jeff. I really appreciate it.
OKay, new question. After I add a method similar to what you guys are suggesting, what statement would I write in my actionPerformed method to call upon that method and get that particular line?
Okay, you guys are doing a great job with giving me a better understanding.

Jeff, are you saying to create 3 separate methods for each line that I want to retrieve? Then use that specific method when I want to call upon that line?
Because to give you an example, in my actionPerformed method, when the calculate button is clicked, I have 3 separate if statements for each loan type (0,1,2). Here is an example of what one looks like:

if (selection == 0)
{
Double data = (Double)calculateLoanOne();
String sourceInput = data.toString();
displayMonthlyPayment.setText(sourceInput);
txtArea.setText(buff.toString());
}

That’s why I was confused with how I would call upon that method in each of the if statements
And to better elaborate on the if statement, each statement is saying if the selection is Loan One, then calculate Loan One’s method. I have 3 separate methods for each loan.
*~Thanks for all the help guys. I resolved my problem. The answer was right in front of me the whole time~*

Register New Account
Reset Password