am only getting the interest amount an not the amount i suppose to pay a month can you please tell me where am going wrong thanks.
import java.util.Scanner;
/**
*
* @author
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//variabled decleared
double rate;
double payment;
//input
System.out.print("Enter Loan Amount:");
double principal = input.nextDouble();
System.out.print("Enter Annual Interest:");
double interest = input.nextDouble();
System.out.print("Total payment type:");
String period = input.next();
System.out.print("Enter Loan Length :");
int length = input.nextInt();
//proces
rate = interest / 100;
if (period.equals("monthly")) {
double n = length * 12;
payment = principal * (rate * Math.pow((1 + rate), n) / Math.pow((1 + rate), n));
System.out.printf("Your Monthly Sum is %.2f",payment);
}
}
Your error is here:
This is the same as having only principal * rate. You are saying x = b * a / a.
Replace to:
n is the number of years, you can not do n = length / 12 to get Monthly. You should do instead: