Monthly payment Calculation Error's Please Help

Hello I have a project for school and my teacher never did a great job at explaining how to do certain aspects of my code. I've done a lot of research on Java and how to get this to work but none worked and i've been working on this code for over 48 hours trying to get this math to work.

Basically I have to make a program that can do monthly payment's.

If I enter a loan amount of :100,000

with the rate of :6

and the years being :30

I should get back about :$599.55

Also if I enter1: 10,000

with the rate being 4.5

years being 3

I should get back about $ 297.47

Here's my code.

Code Java:

package monthypayment2;
import java.util.Scanner;
public class Monthypayment2 {
private static double monthlypay;
private static double monthlypay1;
private static String choice;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double months = 0;
double numyears;
double loanamount;
double rate;
//prompt loan amount
System.out.print("Enter Loan Amount:"); //promp the user
loanamount = in.nextDouble();
//prompt rate
System.out.print("Enter Rate:");
rate = in.nextDouble();
//prompt years
System.out.print("Enter Number of Years:");
numyears = in.nextDouble();
//calculate
monthlypay1 = loanamount * rate / (1 - 1 / Math.pow(1 + rate, months));
System.out.println("The Monthly Payment is: $" + monthlypay1);
System.out.print("Would you like to calculate again?:(y/n)");
choice = in.next();
System.out.println();
}
}

**Any** Help would be appreciated.

also when I run my code I get the monthyly payment is :$Infinity.

When i put months as a value of 12 i will get something like $600000488.65

Re: Monthly payment Calculation Error's Please Help

The user enters numyears, but you never calculate months, which stays 0.

Re: Monthly payment Calculation Error's Please Help

But I thought I needed the months for the Math.pow(1 + rate, Insert another double here);

Re: Monthly payment Calculation Error's Please Help

Your response makes no sense. Of course you need months, and you need it to be something other than zero. Look at your code and determine if months is ever set to something other than zero. If not, you should fix that.

Re: Monthly payment Calculation Error's Please Help

Ok I think the problem is I don't have the rate as a percentage. I've tried setting my month's to a different number but alas I get the same results.

Re: Monthly payment Calculation Error's Please Help

I don't know why we're not communicating. The problem is not that mysterious or difficult. The problem is:

double months = 0;

and that never changes.

Re: Monthly payment Calculation Error's Please Help

Well that and I just realized I was diving by 0.. "(1-1 / math.pow(1 + rate, months));" So I fixed the coding in the math to
Code Java:

monthlypay1 = loanamount * rate / (Math.pow(1 + rate, months)) / (Math.pow(1 + rate, months)-1);

. Thanks for pointing that out.

--- Update ---

This is my new code.

Code Java:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package monthypayment2;
import java.util.Scanner;
/**
*
* @author Aj Miles
*/
public class Monthypayment2 {
private static double monthlypay1;
private static String choice;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double months = 0;
double numyears;
double loanamount;
double rate;
//prompt loan amount
System.out.print("Enter Loan Amount:");
loanamount = in.nextDouble();
//prompt rate
System.out.print("Enter Rate:");
rate = in.nextDouble();
//prompt years
System.out.print("Enter Number of Years:");
numyears = in.nextDouble();
//calculate
monthlypay1 = loanamount * rate / (Math.pow(1 + rate, months)) / (Math.pow(1 + rate, months)-1);
System.out.println("The Monthly Payment is: $" + monthlypay1);
If (monthlypay1 < 0) {
System.out.println("You need to enter positive numerical data!");
}
Else {
System.out.println("Would you like to calculate again?: (Y/N)"); }
}
}
}

Was seeing if anyone can help me out with the boolean statement.

I've looked at a couple of examples of boolean statements but wasn't very helpful. (how to use boolean data type in Java)

Basically what i'm trying to do is if the user enters' say a negative number after everything is done it will tell the user

to enter positive numerical data. If he enters a positive number it will ask him if he wants to continue calculations again?