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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Help needed with loan calculator

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,449
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default 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?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,751
    My Mood
    Mellow
    Thanks
    233
    Thanked 711 Times in 697 Posts

    Default 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. #4
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,449
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default 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?

    Recommended reading: http://www.javaprogrammingforums.com...t-println.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Loan repayment calculator
    By CruelCoin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 14th, 2013, 05:01 AM
  2. Loan Repayment
    By Langolier in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 18th, 2012, 12:29 PM
  3. Loan Payments
    By clarafeb1 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 11th, 2011, 03:36 AM
  4. Help needed with calculator code
    By andys in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 21st, 2011, 08:02 PM