
Getting an Error!
I am not exactly sure whats the case is but I am getting a syntax sort of error:
temp = (1.0/(pow(x,y)));
^
in this line
Code:
import java.util.Scanner;
import java.text.DecimalFormat;
import java.lang.Math;
public class Finance {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Principal Amount: ");
double Principal_Amount = input.nextDouble();
System.out.print("Term of Mortgage in Years: ");
double Term_Mortgage = input.nextDouble();
System.out.print("Interest Rate: ");
double Interest = input.nextDouble();
double payment, r, temp, x, y, future_value, interest_charged;
r = Interest/100.0;
x = 1.0+r/12.0;
y = Term_Mortgage * 12.0;
temp = (1.0/(pow(x,y)));
payment = (Principal_Amount*r/12.0)/(1temp);
future_value = payment * Term_Mortgage * 12.0;
interest_charged = future_value  Principal_Amount;
System.out.println("Principal: $" + Principal_Amount);
System.out.println("Future Value: $"+future_value);
System.out.println("Terms of Loans in Years :" +Term_Mortgage);
System.out.println("Interest Rate :" +Interest);
System.out.println("Interest Charged :" +interest_charged);
System.out.println("Payment: "+payment);
}
}
Thanks

Re: Getting an Error!
Post what is the syntax error?

Re: Getting an Error!
Learn to follow the Java coding conventions. Variable names start with a lowercase letter.
db

Re: Getting an Error!
problem:The method pow(double,double) is undefined for the type Finance
solution:To fix this you have to create method 'pow(double,double)'
Try this code below best of luck dear
import java.util.Scanner;
import java.text.DecimalFormat;
import java.lang.Math;
public class Finance {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Principal Amount: ");
double Principal_Amount = input.nextDouble();
System.out.print("Term of Mortgage in Years: ");
double Term_Mortgage = input.nextDouble();
System.out.print("Interest Rate: ");
double Interest = input.nextDouble();
double payment, r, temp, x, y, future_value, interest_charged;
r = Interest/100.0;
x = 1.0+r/12.0;
y = Term_Mortgage * 12.0;
temp = (1.0/(pow(x,y)));
payment = (Principal_Amount*r/12.0)/(1temp);
future_value = payment * Term_Mortgage * 12.0;
interest_charged = future_value  Principal_Amount;
System.out.println("Principal: $" + Principal_Amount);
System.out.println("Future Value: $"+future_value);
System.out.println("Terms of Loans in Years :" +Term_Mortgage);
System.out.println("Interest Rate :" +Interest);
System.out.println("Interest Charged :" +interest_charged);
System.out.println("Payment: "+payment);
}
private static double pow(double x, double y) {
return 0;
}
}

Re: Getting an Error!
BB Code List  Java Programming Forum
Quote:
Try this code below
Don't spoonfeed. That denies the questioner of a learning opportunity and is not considered helpful.
db

Re: Getting an Error!
Hey,
your problem is that your class Finance doesn't have a method called pow.
I see that you imported the Math class. That's good. It means that you know, that the pow method is in that class.
Now  your mistake here is that you need Java to tell, which pow method to call. Since the pow method within the Mathclass is static (see the API: Math (Java Platform SE 6)) you have to call it statically.
Classes are not really like libraries in C or C++ for instance. You can't just import one and then access it's methods. You either have to instantiate a class (i.e. by calling new)  or, if applicable  call the desired method statically.
Hope this helps, don't want to just give you the example, since that would rob you of a (great) "aha"moment.