Question: Java Program Add the method implementation for the CylinderVolume method so that, given the cylinder diameter d and height h , it calculates the cylinder

Java Program

Add the method implementation for the CylinderVolume method so that, given the cylinder diameterdand heighth, it calculates the cylinder volume using the formula

whereris the cylinder's radius (i.e.,r = d) andhis the cylinder's height

/*

* Program calculates/outputs volume of a cylinder given diameter, height

*/

import java.io.PrintStream;

import java.util.Scanner;

public class Lab

{

/**

* cylinderVolume(double, double) -> double

*

* method consumes diameter and height of cylinder

* method produces cylinder's volume

*

* ex: cylinderVolume(5, 10) -> 196.3

* ex: cylinderVolume(0, 10) -> 0.0

* ex: cylinderVolume(5, 0) -> 0.0

* ex: cylinderVolume(-5, 10) -> 196.3

* ex: cylinderVolume(5, -10) -> -196.3

*

* ADD METHOD IMPLEMENTATION IMMEDIATELY BELOW THE NEXT LINE

*/

/**

* Lab : double, double ; double

*

* program is given the diameter and height of a cylinder

* program calculates and outputs the cylinder's volume

*

* NOTE: YOU ARE NOT ALLOWED TO MODIFY THIS main CODE IN ANY WAY

*/

public static void main(String[] args)

{

// input variables

Scanner in = new Scanner(System.in);

double diameter=0;

double height=0;

// output variables

PrintStream out = System.out;

double volume=0;

// get the cylinder's diameter and volume as user input

out.print("What is the cylinder's diameter? ");

diameter = in.nextDouble();

out.print("What is the cylinder's height? ");

height = in.nextDouble();

// calculate the cylinder's volume

volume = cylinderVolume(diameter, height);

// output the input and output variable data

out.printf("A cylinder with diameter %.1f and height %.1f",

diameter, height);

out.printf(" has volume %.1f ", volume);

} // end main method

} // end Lab

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!