big daddy fatsacks
2[H]4U
- Joined
- Aug 10, 2001
- Messages
- 2,312
for some reason the few times i've tried to use the Math pow() function in java it hasn't worked. i've always worked around it because i've known what the power i was going to raise to was, but that is not the case here. i've tried many different ways of writing this program (in terms of the pow()) but none work. here is what i have at the moment.
if you could tell me how to use pow() correctly i'd greatly appreciate it. with what i have i get a '.class' expected error, and with what i had before i got a "symbol not found" error with an arrow seeming to point to apy within the pow().
thanks
Code:
import java.io.*;
import java.util.*;
import java.lang.Math.*;
public class CompoundInterest {
// define our variables
private static double deposit; // the deposit amount
private static double apr; // the APR of the investment
public static double apy; // the rate to be used in calculations
private static double term; // the term of the investment
private static double year; // the current age of the investment
private static double multiplier; // to be multiplied by the deposit amount in the compoundAnnual method
// begin main class
public static void main(String[] args) throws IOException {
// setup user input stream
BufferedReader stdin = new BufferedReader (
new InputStreamReader (System.in));
// now read the user input
System.out.println("This program will calculate the growth of an investment .");
System.out.println("Enter the deposit amount:");
deposit = Double.parseDouble (stdin.readLine());
System.out.println("Enter the Annual Percentage Rate of the investment:");
apr = Double.parseDouble (stdin.readLine());
apy = (1 + (apr/100));
System.out.println("Enter the term of the investment in years:");
term = Double.parseDouble (stdin.readLine());
// print the results
for (year = 0; year <= term; ++year) {
multiplier = (pow(double apy, double year));
System.out.println("The value of the investment after " + year + " is " + compoundAnnual(deposit, multiplier));
}
if (year > term) {
multiplier = (pow(double apy, double term));
System.out.println("The value of the investment after " + term + " is " + compoundAnnual(deposit, multiplier));
}
} // close main
public static double compoundAnnual(double deposit, double multiplier) {
return (deposit * multiplier);
} // close method compoundAnnual
} // close class compoundAnnual
if you could tell me how to use pow() correctly i'd greatly appreciate it. with what i have i get a '.class' expected error, and with what i had before i got a "symbol not found" error with an arrow seeming to point to apy within the pow().
thanks