http://gyazo.com/72d7bf6a9fcfaecb6f6...png?1348757685
Below is what I have completed until now but I am doing a test case and not getting the correct volume. If someone could help me out as to what I am doing wrong here it would be great.
Code:import java.util.Scanner;
public class A1Q4
{ /**
* Calculate the volume required to cover the track
*/
public static void main( String[] args )
{
// SET UP KEYBOARD INPUT
Scanner keyboard = new Scanner( System.in );
// DECLARE VARIABLES/DATA DICTIONARY
double rLength = 0;
double rWidth = 0;
double tWidth = 0;
double depth = 0;
double clayVolume = 0;
// Read in the given values
System.out.print ("Please enter the width of the rectangle part of the inner field in meters: ");
rWidth = keyboard.nextDouble();
System.out.print ("Please enter the length of the rectangle part of the inner field in meters: ");
rLength = keyboard.nextDouble();
System.out.print ("Please enter the width of the track in meters: ");
tWidth = keyboard.nextDouble();
System.out.print ("Please enter the desired depth of clay in centimeters: ");
depth = keyboard.nextDouble();
// Call method to compute the volume of clay needed.
clayVolume = findClayVolume (rLength, rWidth, tWidth, depth);
// Diplay the result
System.out.println ("\nThe volume of clay needed to cover the track is " + clayVolume + " cubic metres");
}
/**
* Description: include a description of the problem
* solving method (algorithm).
* Parameters (GIVENS):
*/
private static double findClayVolume(double rLength, double rWidth, double tWidth, double depth)
{
// Declaration of the result variable
double clayVolume = 0;
// Declaration of the intermediate variables
double innerTrackVolume = 0;
double wholeTrackVolume = 0;
double depthInM = 0;
// Add code for the method
// Convert the depth in m
depthInM = depth/100;
// Calculate the inner track volume
innerTrackVolume = (rLength*rWidth*depthInM) + (4/3)*(Math.PI*Math.pow((rWidth/2),3)); //*(rWidth/2)*(rWidth/2));
// Calculate the whole track volume
wholeTrackVolume = (rLength*(rWidth + 2*tWidth)*depthInM) + (4/3)*(Math.PI*Math.pow(((rWidth + 2 * tWidth)/2),3)); //*((rWidth + 2 * tWidth)/2)*((rWidth + 2 * tWidth)/2));
// Calculate the track volume by subtracting whole track from inner track
clayVolume = wholeTrackVolume - innerTrackVolume;
// Return the result
return clayVolume;
}
}

