public class Project02 { private double areaTotal; public Project02(double Total) { areaTotal = Total; } public static double TotalArea(double areaTotal) { double []x = {7.5774, 6.4226, 4.3453, 3.4226, 4.5724, 6.6547}; double []y = {4.6340, 6.3660, 6.2321, 4.3660, 2.6340, 2.7679}; double a1 = (x[0] * y[1] + x[1] * y[2] + x[2] * y[0] - y[0] * x[1] - y[1] * x[2] - y[2] * x[0])/2; double a2 = (x[0] * y[2] + x[2] * y[3] + x[3] * y[0] - y[0] * x[2] - y[2] * x[3] - y[3] * x[0])/2; double a3 = (x[0] * y[3] + x[3] * y[4] + x[4] * y[0] - y[0] * x[3] - y[3] * x[4] - y[4] * x[0])/2; double a4 = (x[0] * y[4] + x[4] * y[5] + x[5] * y[0] - y[0] * x[4] - y[4] * x[5] - y[5] * x[0])/2; double []a = {a1, a2, a3, a4}; double result; if(areaTotal == 0 && areaTotal > 3) { result = 0; System.out.println("Done"); } else { result = a[(int)areaTotal] + TotalArea(a[(int)areaTotal - 1]); System.out.println(result); } return result; } }
DRIVER
I run this program using the driver class. However, every time I input a number for areaTotal I get a stackoverflow error. My end goal in this program is to be able to use recursion to successfully print the total in array a using my driver program.