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 15 of 15

Thread: Need help please

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help please

    I have about 4 hours of class time with Java and have an assignment due. I cant figure out how to fix my code. I know Im having issues with my print statements but I just dont understand it. Here is what I have and what is required: Calculate and display the monthly payment amount to fully amortize a $200,000.00 loan over a 30 year term at 5.75% interest. Please help.


    package mortgagecalculator;


    public class MortgageCalculator {
    public static void main(String[] args) {

    }

    double annualInterest = 5.75; //This is the annual interest rate
    double loanAmount = 200000; //This is the loan amount
    double loanLengthInYears = 30; //This is the length of the loan in years


    //Formuals bieng used are:
    double monthlyInterest = annualInterest / 100 /12;
    double loanLengthInMonths = loanLengthInYears * 12;

    double monthlyPayment = (loanAmount * monthlyInterest) / (1 - Math.pow((1 + monthlyInterest), loanLengthInYears));


    System.out.println("MortgageCalculator");
    System.out.println("Annual Interest: 5.75%");
    System.out.println("Loan Amount: $200,000");
    System.out.println("Loan Length: 30 years");
    System.out.println("Monthly Payment: " + currencyFormat.format(monthlyPayment));

  2. #2
    Member
    Join Date
    Aug 2011
    Posts
    55
    Thanks
    5
    Thanked 3 Times in 3 Posts

    Default Re: Need help please

    What is currencyFormat.format. Are they custom class and method? If they are you will need to post the code. I think what you are looking for is the String.format
    method. Take a look at this link: Java Platform SE 7 look at the format method.

    Hope it helps

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help please

    Would it make a difference if that last println statement was replaced like this:


    package mortgagecalculator;


    /**
    *
    * @author Johnny
    */
    public class MortgageCalculator {
    public static void main(String[] args) {

    }

    double annualInterest = 5.75; //This is the annual interest rate
    double loanAmount = 200000; //This is the loan amount
    double loanLengthInYears = 30; //This is the length of the loan in years


    //Formuals bieng used are:
    double monthlyInterest = annualInterest / 100 /12;
    double loanLengthInMonths = loanLengthInYears * 12;

    double monthlyPayment = (loanAmount * monthlyInterest) / (1 - Math.pow((1 + monthlyInterest), loanLengthInYears));


    System.out.println("MortgageCalculator");
    System.out.println("Annual Interest: 5.75%");
    System.out.println("Loan Amount: $200,000");
    System.out.println("Loan Length: 30 years");
    System.out.println(monthlyPayment);

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Need help please

    Quote Originally Posted by kprofgold View Post
    Would it make a difference if that last println statement was replaced like this:


    package mortgagecalculator;


    /**
    *
    * @author Johnny
    */
    public class MortgageCalculator {
    public static void main(String[] args) {

    }

    double annualInterest = 5.75; //This is the annual interest rate
    double loanAmount = 200000; //This is the loan amount
    double loanLengthInYears = 30; //This is the length of the loan in years


    //Formuals bieng used are:
    double monthlyInterest = annualInterest / 100 /12;
    double loanLengthInMonths = loanLengthInYears * 12;

    double monthlyPayment = (loanAmount * monthlyInterest) / (1 - Math.pow((1 + monthlyInterest), loanLengthInYears));


    System.out.println("MortgageCalculator");
    System.out.println("Annual Interest: 5.75%");
    System.out.println("Loan Amount: $200,000");
    System.out.println("Loan Length: 30 years");
    System.out.println(monthlyPayment);
    Does this program even compiling? If no, paste here the errors/exceptions.

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help please

    I get cannot find symbol, identifier expected, and illegal start of type errors

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Need help please

    Can you copy the errors and paste here?

  7. #7
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help please

    I think this is the error Im not very good at this sorry.

    Listening on javadebug
    Not able to submit breakpoint LineBreakpoint MortgageCalculator.java : 81, reason: The breakpoint is set outside of any class.
    Invalid LineBreakpoint MortgageCalculator.java : 81
    User program running
    User program finished

  8. #8
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Need help please

    Well, i don't know why aren't you trying to understand what i mean to say.
    Simply,
    double annualInterest = 5.75; //This is the annual interest rate
    double loanAmount = 200000; //This is the loan amount
    double loanLengthInYears = 30; //This is the length of the loan in years
     
     
    //Formuals bieng used are:
    double monthlyInterest = annualInterest / 100 /12;
    double loanLengthInMonths = loanLengthInYears * 12;
     
    double monthlyPayment = (loanAmount * monthlyInterest) / (1 - Math.pow((1 + monthlyInterest), loanLengthInYears));
     
     
    System.out.println("MortgageCalculator");
    System.out.println("Annual Interest: 5.75%");
    System.out.println("Loan Amount: $200,000");
    System.out.println("Loan Length: 30 years");
    System.out.println(monthlyPayment);
    paste this piece of code inside main() and then check the closing and opening braces.

  9. #9
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help please

    Ok thank you... I was closing the code before I had even inputted anything and I had to restart my NetBeans for the code to run. But now the calculation is off and I think it may be within the math. Here are my results:

    MortgageCalculator
    Annual Interest: 5.75%
    Loan Amount: $200,000
    Loan Length: 30 years
    -6214.908191559089 (I know this should a positive # lol)

  10. #10
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Need help please

    (1 - Math.pow((1 + monthlyInterest), loanLengthInYears))
    It's giving the negative value.
    Last edited by Mr.777; December 19th, 2011 at 01:58 AM.

  11. #11
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help please

    I still havnt been able to fix the math yet.... but I noticed I am also getting a gray line under my loanLengthInMonths...the error is not a known variable in the current context

  12. #12
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Need help please

    but I noticed I am also getting a gray line under my loanLengthInMonths
    It's not an error but it is coz the variable loanLengthInMonths is not being used anywhere after assigning value to it.

    Also, i don't know what you are supposed to do, might be the problem in your formulas.

  13. #13
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help please

    Here is what I am supposed to calculate: Calculate and display the monthly payment amount to fully amortize a $200,000.00 loan over a 30 year term at 5.75% interest. And thank you for all of your help.

  14. #14
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help please

    I think I just figured it out. Heres the code

    public class MortgageCalculator {


    public static void main(String[] args) {
    double annualInterest = 5.75; //This is the annual interest rate
    double loanAmount = 200000; //This is the loan amount
    double loanLengthInYears = 30; //This is the length of the loan in years


    //Formuals bieng used are:
    double monthlyInterest = annualInterest /100/12;
    double loanLengthInMonths = loanLengthInYears * 12;

    double monthlyPayment = (loanAmount * monthlyInterest) * (1 + Math.pow((1 - monthlyInterest), loanLengthInYears));


    System.out.println("MortgageCalculator");
    System.out.println("Annual Interest: 5.75%");
    System.out.println("Loan Amount: $200,000");
    System.out.println("Loan Length: 30 years");
    System.out.println(monthlyPayment);
    }
    }

  15. #15
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Need help please

    Good Luck.