After having done the hand calculation and pseudocode for a program that models inflating a...

Question:

After having done the hand calculation and pseudocode for a program that models inflating a spherical balloon, now implement the task in Java. Remember, first the balloon is inflated to have a certain diameter (which is provided as an input). Then you inflate the balloon so that the diameter grows by an inch, and display the amount the volume has grown. Repeat that step: grow the diameter by another inch and show the growth of the volume.

Complete the following program.

import java.util.Scanner;
public class Balloon { public static void main(String[] args)
 {
Scanner in = new Scanner(System.in);
System.out.print("Diameter: ");
double diameter = in.nextDouble();
. . .
System.out.printf("Increase: %.0f", . . .);
System.out.println();
. . .
System.out.printf("Increase: %.0f", . . .);
System.out.println();
}
}

Pi Number in JAVA:

While one can create a variable, such as with the name 'pi' and assign some close value to real pi, he can also use the built-in pi number in java by accessing via Math.PI.

Answer and Explanation: 1

Become a Study.com member to unlock this answer!

View this answer

Java code below:

import java.util.Scanner;
public class Balloon {
    public static void main(String[] args) {
   &...

See full answer below.


Learn more about this topic:

Loading...
Methods in Java: Definition & Example

from

Chapter 6 / Lesson 4
103K

A method in a Java program provides a set of instructions to be executed. Explore the different components of a method, such as its parameters and ability to return a value, and learn how to create a method.


Related to this Question

Explore our homework questions and answers library