I have to create an Car Payment app in java that prompts user for principal owing (P), interest rate (r) and the number of monthly payments (m) The monthly car payment MUST be calculated using this formula:
P(r/12)/(1-(1+r/12)^-m)
This is what I have so far...
import java.util.Scanner;
import java.lang.Math; //importing Scanner, Math, and NumberFormat classes
import java.text.NumberFormat;
class Exercise13{
public static void main(String[] args){
Scanner input=new Scanner(System.in); //creating Scanner
double principal, rate, numberOfMonths, payment; //declaring varibles
System.out.print("Principal: ");
principal=input.nextDouble();
System.out.print("Interest Rate: "); //requesting and storing user input
rate=input.nextDouble();
System.out.print("Number of monthly payments: ");
numberOfMonths=input.nextDouble();
input.close(); //closing Scanner
payment=principal*(rate/12)/(1-(1+rate/12*)Math.pow(payment, -numberOfMonths)); //calculating monthly payment. Error in this line
NumberFormat money =NumberFormat.getCurrencyInstance(); //Formatting output
System.out.println("The monthly payment is:" (money.format(payment));
}
}
It does not compile, and I'm really frustrated because I have spent a long time and I cannot figure this out.
Any help is appreciated