954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Table Loan

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);
      	}
      	}
      	}
fraandres
Newbie Poster
7 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 
symbol: method pow(double,int) location: class Math


That's what you need to look at, not "monthlyPayment" variable. It said that the method pow() accepts double & integer, but Math.pow() accepts double & double. Here is the link to the class doc http://download.oracle.com/javase/6/docs/api/java/lang/Math.html .

Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 

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

fraandres
Newbie Poster
7 posts since Nov 2009
Reputation Points: 10
Solved Threads: 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...

Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 

I'm using jGrasp.

is it printing the MonthlyPayment as well?

fraandres
Newbie Poster
7 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

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
...
...
*/
Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 

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

lbarowski
Newbie Poster
12 posts since Dec 2009
Reputation Points: 14
Solved Threads: 3
 

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)); 



} 

} 

}
fraandres
Newbie Poster
7 posts since Nov 2009
Reputation Points: 10
Solved Threads: 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));
Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: