Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Clueless as to what is wrong.

  1. #1
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Clueless as to what is wrong.

    I have written some code to "print out three lines for each loan, giving the amount of monthly payments, the interest paid over the life of the loans, and the total amount paid back over the life of the loan, with appropriate wording."
    I was given a formula to figure out the monthly payment and I get the monthly payment that is given so I know for a fact that the formula in my code is right. But the problem is somewhere where I calculate the interest and total amount paid.
    Java Code:
    import java.io.*;
    import java.util.*;
    
    public class Interest
    {
    {
         Scanner Console = new Scanner(System.in);
         System.out.print("The amount I wish to borrow: ");
         double Borrowed = Console.nextDouble();
         
         System.out.print("The loan rate I can get is: ");
         double Rate = Console.nextDouble();
         
         System.out.print("The number of months it will take me to pay off the loan is: ");
         double Month = Console.nextDouble();
         
         double MP = Borrowed * (Rate/1200.0) * Math.pow(1+Rate/1200.0,Month)/(Math.pow(1+Rate/1200.0,Month)-1);
         System.out.println(" ");
         
         double newMP = Math.round(MP*100.0)/100.0;
         System.out.println("The monthly payment will be: " + newMP);
         
         double totalinterest = (newMP*Month)-Borrowed;
         double newtotalinterest = Math.round(totalinterest*100.0)/100.0;
         System.out.println("The total amount of interest paid is: " + newtotalinterest);
         
         double Totalpaid = newMP*Month;
         System.out.println("The total amount paid is: " + Totalpaid);
    When you run the program, these numbers should be typed in:

    The amount I wish to borrow is? 7500
    The loan rate I can get is? 14.5
    The number of months it will take me to pay off the loan is? 36

    The numbers you should be getting are:
    My monthly payments will be $ 258.16
    Total Interest Paid is $ 1793.66
    Total Amount paid is $ 9293.66

    My monthly payment number is the same as the one given but my Total Interest paid and Amount paid are off by 10 cents. I have been thinking about this problem all day and can not find a solution. It is probably staring me right in the face but can anyone LEAD me in the right direction?

  2. #2
    JavaAdviser is offline Member
    Join Date
    Sep 2012
    Posts
    26
    Rep Power
    0

    Default Re: Clueless as to what is wrong.

    First of all statements can only be executed in methods.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Clueless as to what is wrong.

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Clueless as to what is wrong.

    If you're not using an IDE to create your programs, you'll want to compile your code early and often and making sure to fix any compilation errors before trying to add new code. That would have saved you a lot of trouble here in your program above.

  5. #5
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Re: Clueless as to what is wrong.

    Quote Originally Posted by Fubarable View Post
    If you're not using an IDE to create your programs, you'll want to compile your code early and often and making sure to fix any compilation errors before trying to add new code. That would have saved you a lot of trouble here in your program above.
    I'm using BlueJ. No, don't suggest me others or say how bad it is. The program runs, like I stated above, but I am off 10 cents which is my problem.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Clueless as to what is wrong.

    Quote Originally Posted by Biscuittickler View Post
    The program runs, like I stated above
    The code you posted won't run. Heck, it won't even crawl.

    db
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Clueless as to what is wrong.

    Quote Originally Posted by Biscuittickler View Post
    I'm using BlueJ. No, don't suggest me others or say how bad it is. The program runs, like I stated above, but I am off 10 cents which is my problem.
    No, the code you've posted won't even compile, since as pointed out, you've got statements sitting out naked in the class when they should be within a main method (which the class doesn't even have). If you have different code that's actually compiling and running, and if you're still having problems, then you'll want to post the new code and not waste our time with code that doesn't reflect the current problem and that doesn't run.

  8. #8
    MrPosotive is offline Member
    Join Date
    Sep 2012
    Posts
    68
    Rep Power
    0

    Default Re: Clueless as to what is wrong.

    Your in my AP Computer Scinece class... Just thought id throw that out there

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. I can't find anything wrong with this but somehow it's wrong.
    By Biscuit Tickler in forum New To Java
    Replies: 2
    Last Post: 09-12-2012, 09:28 PM
  3. What am I doing wrong here?
    By fatabass in forum New To Java
    Replies: 3
    Last Post: 01-21-2012, 09:45 PM
  4. Im clueless, please help
    By truant420 in forum New To Java
    Replies: 14
    Last Post: 03-02-2011, 12:59 AM
  5. What am I doing wrong?
    By yankeefan9874 in forum New To Java
    Replies: 1
    Last Post: 04-16-2010, 08:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •