Your Questions About Mortgage Calc

Nancy asks…

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~*

admin answers:

I’ve always liked the Scanner api for this. You could try something along the lines of

File file = new File(pathOnLocalDisk);
Scanner scanner = new Scanner(file);

then you can try something like
String lineOne, lineTwo, lineThreel
if(scanner.hasNext())
lineOne = scanner.nextLine()

if(scanner.hasNext())
lineTwo = scanner.nextLine()

if(scanner.hasNext())
lineThree = scanner.nextLine()

OR

String [] strings = new String[];
int count=0;
while(scanner.hasNext()){
strings[count] = scanner.next();
count++;
}

I have provided the links to the File and Scanner API below

Edit: changed next() to nextLine(), if you are interested in using something other than a line break as your delimeter between the interest rates you can look into the useDelimiter(Pattern pattern) method on Scanner

2nd Question:
If you mean get that particular line of the file I suggest reading the file once at the beginning of the program as file I/O is fairly slow. Store all of the lines of the file in a global array or List of Strings in the class and when you want to access line x you could have a method somewhat along the lines of

public List fileInputList;

public String getInputLine(int lineNumber){
if(fileInputList == null){
rereadFile();
}
if(lineNumber >= fileInputList.size())
return “”;

return fileInputList.get(lineNumber);
}

Ken asks…

Please help to correct my java code?

I have been correcting the arrays, and still need help with how I am putting this together. I have called out the interest rates, years, and need to printout all three mortgage payments for only one month. Any suggestions?

import java.text.DecimalFormat;

//
public class MortgagePayment
{
public void calc(double interest, double principle, int monthlypayments)
{

//Declare and construct the variables
DecimalFormat decimalPlaces = new DecimalFormat(“.00″);
double monthlypayments, principle, interest, interestAmount, payment;

int amount, i, paymentsPerPage, lengthOfPause;

// Variable Declaration
int principal[] = {200000, 200000, 200000};// Principal for each calculation
double interestRate[] = {5.35, 5.50, 5.75};// Interest Rate for each interest rate
int totalYears[] = {7, 15, 30};// Length in years for each loan
double monthlyInterest[] = {0, 0, 0};// Monthly Interest
int totalMonths[] = {0, 0, 0};// Number of Months
double monthlyPayment[] = {0, 0, 0};// Monthly Payment

// Calculations Loop
for (int i = 0; i < 3; i++){
monthlyInterest[i] = interestRate[i] / (12 * 100);
totalMonths[i] = totalYears[i] * 12;
monthlyPayment[i] = principal[i] * (monthlyInterest[i] /
(1 – (Math.pow((1 + monthlyInterest[i]),(-totalMonths[i])))));
}

//Output to screen
System.out.println("Principle = $"+decimalPlaces.format(principle)); //The loan amount
System.out.println("Interest Rate ="+interest*100 +"%"); //The interest rate
System.out.print("Payment per Month = $"); //The monthly payment amount
System.out.println(decimalPlaces.format(payment));
System.out.println("********************");
System.out.println("********************");

for(i = 1; i <= 1; i++)
{
System.out.println("Payment " + i + ":");
System.out.println("———-");

System.out.println("Payment Amount: $ " + decimalPlaces.format(payment));
interestAmount = ((interest / 12) * principle);
System.out.println("Interest Amount: $ " + decimalPlaces.format(interestAmount));

// You also have to calculate interest and add that back in.
principle = (principle – payment) + interestAmount;
System.out.println("Loan Balance: $ " + decimalPlaces.format(principle));
System.out.println("———-");
System.out.println("");
if(((i – 1) % paymentsPerPage) == 0)
{
try{Thread.sleep(lengthOfPause * 1000);} //This is a pause function.
catch(InterruptedException ie){}
}
}
}
}

admin answers:

First of, your variable declaration

if you want to declare an array to type say int with name say myintegerarray it has to take the form
int[] myintegerarray = {….}

notice you have to tell java what type of variable array myintegerarray is first, when you use myintegerarray[] java tries to create an array of type myintegerarray which unless defined in a separate class will produce a compilation error.

My suggestion, fix your variable declarations first, re – run and if there is anything else, let us know and I will be more than happy to help,

Regards,

David

ps – what IDE are you using (I recommend Eclipse for CMD development – Netbeans for GUI development)

James asks…

Am I greedy for living at home?

Here’s the deal, I can easily move out anytime, it’s just the fact that I’m extremely cheap and I know I’ll just be throwing money down the toilet if I rent an apartment or live with room mates. Plus I don’t like dealing with people’s nonsense (plus the fact that I’ve seen one too many Judge Judy episodes to convince me not to) so I’m always going to refuse this “living” route.

I know that by staying at home, I’m saving TENS of thousands of dollars per year that would have ALL gone to interest on a mortgage. My plan is to stay at home until I have enough money under my belt to buy at least 80-90% of a nice house’s principle cost. It’s just math really, and I’ve done enough Calc 2 problems in my life to see how much interest adds up.

Some other info, I’m in my early twenties, there’s no one else at home except my parents, I’ve stopped going to school and working full time at $40k/year job. I’m also completely debt-free, a true rarity among my peers. My plan has me *owning* a VERY nice house by age 30, with no interest paid anywhere. Although tbh, living at home until then seems a bit unlikely.

I’d now like to know people’s thoughts.
Btw, I did forget to mention, I do pay my parents rent – they do not “support” me in any way other than providing me a room. In fact, it’s quite the opposite. I “support” them by buying groceries, doing all the yard work, cleaning, doing repairs, ect. By no means am I “egocentric.”

admin answers:

You’re not greedy if you are paying your parents enough to cover the cost of keeping you, and are respectful of their home.

Jenny asks…

math questions?

Pretty basic stuff. I’ve solved them already but I’m looking for the correct answers to check myself.
1. jim has a 134,200 home with a 61,625 mortgage. he has 8,224 in savings and an additional 5,197 in a mutual fund account. He owes 9,560 on his car and 3,000 on his credit card. What’s his networth?
2. (-8xsquared+5)+(-5vsquared-8)
I got -13xsquared – 3
3. find the prime factorization of 88
(can’t figure that one out)
4. factor:
(numbers followed by letters represent being raise to a power since i dont know how to do it on my keyboard. Ex: u2= u to the second power)
u2+6uv+36v2
I cheat when I factor (downloaded a program on my calc) so when these multiple coefficients came into place, i got lost.

admin answers:

1) $73,436.00
2) -13x squared -3
3) 88 =
8 * 11…………… 11 is a prime factor
while 8 breaks down into
4 * 2 ………….2 is a prime factor
while 4 breaks down into
2 * 2……………..both 2′s are prime factors
4) can’t be factored

Chris asks…

Young couple with pretty good income, but low down payment, can I buy a home?

I’ve gotten through advanced calc and computational analysis courses, but navigating the world of finance and mortgages is still a bit daunting.. any help would be appreciated:

I make $75-80k and my spouse makes about 40. We’ve been renting in the MD-DC-VA suburbs for 4+ years, with perfect rental history (paying about 1300/mo), and have average credit.

We’d be first-time buyers. I know we could easily swing the monthly payments, it’s just the initial costs I’m not sure about.

Anyway, given this income (total about 110k/year before taxes), and a small (say 3-5k) down payment. What options, if any, are there for buying a 250k-300k (town)home? (we’re 25 years old if that matters)
I’m aware of FHA loans, but how/if they would help lower the inital costs is still a mystery.

Thanks!
fyi you did sound caustic, and the plan is to wait at least 4 months. I’m looking for some info and others’ experience.

admin answers:

I am a loan officer in the Northern VA area. I can tell you that unless you are in some sort of the military, you will need to put down payment into purchasing a home. If you are military, you could do a VA loan and get 100% financing. If you aren’t military, FHA will be the way to go. There is no down payment assistance any longer from any kind of non-profit groups such as Ameridream (that went away on October 1, 2008). As of January 1, 2009, you are required to put 3.50% into the purchase with FHA. If you have a 401K, you are allowed to borrow against it for the purchase of a home. If that is not an option, you can get the money gifted to you by a family member. The other good news for you is that if you purchase your home prior to July 1, 2009, you can get the first time homeowner tax credit of $7,500, so if you do need to reimburse your 401K, you can do it with this money. It sounds like you will qualify with no problem with your credit and with your income, but make sure you have the down payment in order, if not, you will need to save up for the 3.50% of the purchase price. The closing cost can be taken care of by the seller.

Powered by Yahoo! Answers

Related posts:

  1. Your Questions About Mortgage Loan Payment Calculator
  2. Your Questions About Mortgage Loan Payment Calculator
  3. Your Questions About Mortgage Calc
  4. Your Questions About Mortgage Loan Calculator
  5. Your Questions About Mortgage Loan Payment Calculator

Leave a Reply