I'm working on a program that estimates pi using the Ramanujan series. In the series, it requires me to calculate the factorial of a couple expressions, which I have a class written for. I had used the class for a previous assignment, explaining the tests at the top of the class. My issue comes into play when I try to create the Factorial object to use Factorial.calculate(nthNum)
. I've tried everything I can think of, searched many forums, went back over my notes, and I cannot figure out why this error keeps happening.
.\Ramanujan.java:9: error: cannot find symbol
Factorial f = new Factorial();
^
symbol: class Factorial
location: class Ramanujan
.\Ramanujan.java:9: error: cannot find symbol
Factorial f = new Factorial();
^
symbol: class Factorial
location: class Ramanujan
2 errors
error: compilation failed
If someone could explain to me why the symbol cannot be found, it would be very helpful. Thank you.
public class Ramanujan {
public static void main (String[] args){
String nthRamNumString = args[0];
int nthRamNum = Integer.parseInt(nthRamNumString);
findRamNum(nthRamNum);
}
public static double findRamNum(int nthNum){
Factorial f = new Factorial();
double factNum = f.calculate(nthNum);
double firstVal = ((2 * Math.sqrt(2)) / 9801);
double piNum = 0;
for (int i = 0; i <= nthNum; i++){
piNum = piNum + (4 * factNum) * (1103 + (26390 * nthNum)) /
(Math.pow(factNum, 4) * (Math.pow(396, 4 * nthNum)));
}
double finalPiVal = (firstVal * piNum);
return 1 / finalPiVal;
}
}
public class Factorial {
public static void main (String[] args){
String value = args[0];
Long n = Long.parseLong(value);
if (n > 20){
System.out.println("Value must be less than 20!");
System.exit(0);
}
else if (n < 0){
System.out.println("Value must be greater than 1!");
System.exit(0);
}
else{
System.out.println(calculate(n));
}
Long result = calculate(0);
if (result == 1){
System.out.println("Factorio.calculate(0) returned " + result + ". Test passed!");
}
else{
System.out.println("Factorio.calculate(0) returned " + result + ". Test failed!");
}
result = calculate(5);
if (result == 120){
System.out.print("Factorio.calculate(5) returned " + result + ". Test passed!");
}
else{
System.out.print("Factorio.calculate(5) returned " + result + ". Test failed!");
}
}
public static long calculate(long n){
long factNum = 0;
if (n == 0){
return 1;
}
else{
for (int i = 0; i <= n; i++){
factNum = factNum + (n * (n - 1));
}
}
return factNum;
}
}