Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions