0

I'm getting a error code : java:23: error: cannot find symbol
monthlyPayment=(balance*(interest/12))/(1-(Math.pow(1/(1+(interest/12)),(numberOfYears*12))));
^
symbol: method pow(double,int)
location: class Math
1 error

it's pointing at Math.pow, but I dont understand what else to do thank you for any help.

import java.util.*;
 
   public class Loan
   {
   
   
   
      public static void main(String[] args)
      {
      Scanner input= new Scanner (System.in);
      double monthlyPayment=0;
      double principal=0;
      
      
      System.out.println("Loan Amount : ");
		double balance=input.nextDouble();
		System.out.println("Number of Years :   ");
		int numberOfYears=input.nextInt();
		System.out.println("Annual Interest Rate :   ");
		double interest=input.nextDouble();
		double monthlyInterestRate=interest/12;
		interest= monthlyInterestRate *balance;
      monthlyPayment=(balance*(interest/12))/(1-(Math.pow(1/(1+(interest/12)),(numberOfYears*12))));
		
      for (int i=1; i<=numberOfYears *12; i++)
      {
      
      //interest= monthlyInterestRate *balance;
      //monthlyPayment=(balance*(interest/12))/(1-(Math.pow(1/(1+(interest/12)),(numberOfYears*12))));
		
      
      principal = monthlyPayment - interest;
      balance= balance - principal;
      System.out.println(i + "\t\t" + interest
      	+"\t\t" + principal + "\t\t" + balance);
      	}
      	}
      	}
3
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by Taywin
0

I have try doing it with a pow(double, double) and is the same message

0

Hmm... What IDE are you using? What Java version? I used Texpad using Java 6 to compile and run, it works fine... Though, the answer from the computation (table) is all wrong...

Edit: Hmm... What's wrong with JGRASP... Let me check...

Edited by Taywin: n/a

0

I'm using jGrasp.

is it printing the MonthlyPayment as well?

Edited by fraandres: n/a

1

Below is the output I get... By the way, you should use "System.out.print" instead of "System.out.println" when you accept the input from a user...

/*
Loan Amount:
10000
Number of Years:
5
Annual Interest Rate:
.1
1  83.33333333333    69361.11111111111   -5961.11111111111
2  83.33333333333    69361.11111111111   -128722.22222222222
3  83.33333333333    69361.11111111111   -198083.33333333333
4  83.33333333333    69361.11111111111   -267444.44444444444
...
...
*/

Edited by Taywin: n/a

0

I'm guessing you have a class named "Math" in the same directory, and it is using that instead of java.lang.Math.

0

What I'm trying to do now is to make the answers two decimal places. it seems it not working any suggestions thank you

import java.util.*; 

import java.text.*;

public class Loan 

{ 






public static void main(String[] args) 

{ 
Scanner input= new Scanner (System.in); 

double monthlyPayment=0; 

double principal=0; 







System.out.print("Loan Amount : "); 

double balance=input.nextDouble(); 



System.out.print("Number of Years : "); 

double numberOfYears=input.nextInt(); 

System.out.print("Annual Interest Rate : "); 

double interest=input.nextDouble(); 



double monthlyInterestRate=interest/12; 



monthlyPayment=(balance*(interest/12))/(1-(Math.pow(1/(1+(interest/12)),(numberOfYears*12)))); 

System.out.println("Monthly Payment: "+monthlyPayment); 


for (int i=1; i<=numberOfYears *12; i++) 

{ 






interest= monthlyInterestRate *balance; 

principal = monthlyPayment - interest; 

balance= balance - principal; 

DecimalFormat df = new DecimalFormat("#.00"); 

System.out.println(df.format(i + "\t\t" + interest 

+"\t\t" + principal + "\t\t" + balance)); 



} 

} 

}

Edited by fraandres: n/a

0

Line 70, try changing it to...

DecimalFormat df = new DecimalFormat("#.##");

Then line 72, you are supposed to pass in a double/float without any string.

System.out.println(i+"\t\t"+df.format(interest));
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.