Methods: Pyramid Volume
Sebastian Wright
This is my task that I have to do:
Define a method pyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volume of a pyramid with a rectangular base.
Here is my code:
import java.util.Scanner;
public class CalcPyramidVolume {
public static void pyramidVolume (double baseLength, double baseWidth, double pyramidHeight) { baseLength = 1.0; baseWidth = 1.0; pyramidHeight = 1.0; double pyramidVolume = ((baseLength * baseWidth) * pyramidHeight) / 3;
}
public static void main (String [] args) { System.out.println("Volume for 1.0, 1.0, 1.0 is: " + pyramidVolume(1.0, 1.0, 1.0)); return;
}
}I can edit only the section of code where I created the pyramidVolume method call. I am getting an error that says 'void' type not allowed here and it is pointing the to system.out line which i can not edit. I am very confused on why it is giving me an error on that line.
41 Answer
pyramidVolume return type is void. Change return type to double as below:
public static double pyramidVolume (double baseLength, double baseWidth, double pyramidHeight) { double pyramidVolume = ((baseLength * baseWidth) * pyramidHeight) / 3; return pyramidVolume;
} 5