Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Methods: Pyramid Volume

Writer 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.

4

1 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy