Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Help needed with loan calculator

1. ## Help needed with loan calculator

Hi all,

Trust all is well.

I am currently attending an introduction to java course and need to present my final assignment by the end of the month. The assignment consists of a java program that is able to calculate the amount of money that the bank can give you for your home loan, on the basis of the amount of money you (an your partner) earn, the age and the amount of years. The amount of money that the bank will give you is 33% of your total income, but that amount includes also a 3% rate of interest.

I have made some code within a JFrame, (which for most of you is quite straight forward), and right now I cannot get the underneath to work:

private void btn_Get_QuoteActionPerformed(java.awt.event.Action Event evt) {

int txt_Age_Int = 0;
int txt_SpouseAge_Int = 0;
double txt_Monthly_Income_Int = 0.0;
double txt_Spouse_Monthly_Income_Int = 0.0;
int Ret_Age = 65;
int Loan_Repay_Years = 0;
double Total_Income = 0.0;

if((rbtn_Single.isSelected()) || (txt_Age_Int > txt_SpouseAge_Int))
{
try
{
txt_Monthly_Income_Int = Double.parseDouble(txt_Monthly_Income.getText());
txt_Age_Int = Integer.parseInt(txt_Age.getText());
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "Numeric Values ONLY", "Error", JOptionPane.CANCEL_OPTION);
}

Total_Income = txt_Monthly_Income_Int;
Loan_Repay_Years = (Ret_Age - txt_Age_Int);

}

else if ((rbtn_Married.isSelected()) && (txt_SpouseAge_Int > txt_Age_Int))
{
try
{
txt_Spouse_Monthly_Income_Int = Double.parseDouble(txt_Spouse_Income.getText());
txt_SpouseAge_Int = Integer.parseInt(txt_SpouseAge.getText());
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "Numeric Values ONLY", "Error", JOptionPane.CANCEL_OPTION);
}

Total_Income = (txt_Spouse_Monthly_Income_Int) + (txt_Monthly_Income_Int);
Loan_Repay_Years = (Ret_Age - txt_SpouseAge_Int);

}

String Outmessage = " Years of Repayment " + Loan_Repay_Years + "\n" +
"\n Total Income is " + Total_Income;

JOptionPane.showMessageDialog(null,Outmessage, "Qoutation", JOptionPane.INFORMATION_MESSAGE);

}

It looks like the code is totally ignoring the 'else if' statement and reporting nothing when the married button is selected.

Could you give me some help please ? And maybe even any ideas of how to develop such assignment, in terms of whether creating other classes, or use some forms of functions and methods?

Regards

The Newbie

2. ## re: Help needed with loan calculator

Please don't post multiple copies of the same question in different subforums. I've deleted your duplicate post.

When posting code, please use the highlight tags to preserve formatting. Code you post should be in the form of an MCVE, not a disconnected snippet like you've posted, but not your whole project either.

You might also want to use more descriptive post titles in the future. "Need help" doesn't really tell us anything, and makes your post more likely to be skipped over.

As for your problem, have you stepped through this with a debugger or at least added print statements to figure out what's going on? What is the value of each variable being used in the if statement in question?

3. ## re: Help needed with loan calculator

Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

4. ## re: Help needed with loan calculator

Hi Kevin,

Thanks for the reply and apologies for the duplication of posts!

I am going to re post my query once again, only that this time I will be using the proper procedure when posting codes.

Could you guide me through?

No I have not used a debugger, as I am quite a newbie. I am using netbeans as an IDE. Could you guide me through please?

Regards

5. ## re: Help needed with loan calculator

You don't have to post yet another duplicate. You can just edit this post.

What happened when you googled "netbeans debugger"? What happened when you simply added some print statements?