# Why is this not working?

• September 28th, 2012, 02:34 PM
Itspoizonous
Why is this not working?
Hi all,
I have to write a program that uses this equation:
Attachment 1440

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:)
• September 28th, 2012, 03:18 PM
Norm
Re: Why is this not working?
Quote:

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.
• September 28th, 2012, 04:38 PM
Itspoizonous
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);