I have a project where I have four methods. The 2nd and 3rd methods (with, and without respectively) both have arrays in them where the user inputs data.
An example of the 2nd method is below. The 3rd is much like it
public static void billWithoutGardens()
{
Scanner input = new Scanner(System.in);
double withoutGardens[] = new double[12];
System.out.println("Please enter energy bills for year without rooftop gardens");
// 12 part array, one for each month
System.out.print("Please enter energy bill for January: ");
withoutGardens [0] = input.nextDouble();
System.out.print("Please enter energy bill for February: ");
withoutGardens [1] = input.nextDouble();
System.out.print("Please enter energy bill for March: ");
withoutGardens [2] = input.nextDouble();
System.out.print("Please enter energy bill for April: ");
withoutGardens [3] = input.nextDouble();
System.out.print("Please enter energy bill for May: ");
withoutGardens [4] = input.nextDouble();
System.out.print("Please enter energy bill for June: ");
withoutGardens [5] = input.nextDouble();
System.out.print("Please enter energy bill for July: ");
withoutGardens [6] = input.nextDouble();
System.out.print("Please enter energy bill for August: ");
withoutGardens [7] = input.nextDouble();
System.out.print("Please enter energy bill for September: ");
withoutGardens [8] = input.nextDouble();
System.out.print("Please enter energy bill for October: ");
withoutGardens [9] = input.nextDouble();
System.out.print("Please enter energy bill for November: ");
withoutGardens [10] = input.nextDouble();
System.out.print("Please enter energy bill for December: ");
withoutGardens [11] = input.nextDouble();
System.out.println(Arrays.toString(withoutGardens));
return;
I am trying to use the 4th method to calculate the difference between each of the elements of the 2 arrays. I do not know how to do this and after much searching around I am turning to the good folks at Stackoverflow.
the 4th method is as such
public static void calculateSavings(double withoutGardens[], double withGardens[])
{
}
Is that the correct way to start out that method in order to achieve my goal of calculating difference?
EDIT - how would I call the 4th method back into the main?
calculateSavings(withoutGardens[], withGardens[]);
that is how I have it as of now and I get errors on it that it "cannot be resolved to a variable".
calculateSavings(withoutGardens, withGardens);