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

Thread: Why is this not working?

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why is this not working?

    Hi all,
    I have to write a program that uses this equation:
    Untitled1.png

    when you type in the numbers 7500, 14.5, and 36 you should get:

    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


    Why doesnt it work? Heres the code:

    import java.io.*;
    import java.util.*;
    public class Prog58i
    {
    public static void main (String[] args)
    {
    //input
    System.out.print("the amount I wish to borrow is? ");
    Scanner a = new Scanner(System.in);
    double borrow = a.nextDouble(); //P
    System.out.print("The loan rate I can get is? ");
    Scanner b = new Scanner(System.in);
    double rate = b.nextDouble(); //R
    System.out.print("The number of months it will take me to pay of this loan is? ");
    Scanner c = new Scanner(System.in);
    double months = c.nextDouble(); //M

    //Processing
    double MP = borrow * (rate/1200) * Math.pow((1+rate/1200), months) / (Math.pow((1+rate/1200), months)- 1);
    double intrest = (MP * months) - borrow;
    double repaid = (MP*months);
    //Output

    System.out.print( "My monthly payments will be $" +MP +"\n");
    System.out.print( "Total Interest Paid is $" +intrest +"\n");
    System.out.print( "Total Amount Paid is $" +repaid +"\n");


    Im very new to Java so please make the answers as simple as possible. Thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,053
    Thanks
    52
    Thanked 2,280 Times in 2,251 Posts

    Default Re: Why is this not working?

    Why doesnt it work?
    Please explain what happens? What doesn't work? If you are getting error messages, please copy and pasted the full text here.
    If the output is wrong, copy and paste the full contents of the console window showing your input and the program's output.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why is this not working?

    Never mind I got it to work. The problem I was having was that the output kept coming out as 0.0 instead of 283.17.
    The problem was that there was an error in the typing of the formula. It should have been:

    double MP = borrow * (rate/1200) * (Math.pow((1+rate/1200), months)) / (Math.pow((1+rate/1200), months)- 1);

    Instead of:

    double MP = borrow * (rate/1200) * Math.pow((1+rate/1200), months) / (Math.pow((1+rate/1200), months)- 1);


    Thanks for the fast reply though

Similar Threads

  1. Working with $
    By whome in forum What's Wrong With My Code?
    Replies: 20
    Last Post: April 11th, 2012, 03:00 PM
  2. not sure why the 'else is not working
    By reddevilggg in forum Loops & Control Statements
    Replies: 3
    Last Post: September 30th, 2011, 03:54 PM
  3. Why isn't this working?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 14
    Last Post: January 21st, 2011, 03:08 PM
  4. Cannot seem to get this working
    By OttawaGuy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 28th, 2010, 03:41 PM
  5. Replies: 4
    Last Post: January 26th, 2009, 11:03 PM