Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3573357 • Letter: 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.

Complete the following file:

Balloon.java

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();
  
while (diameter >= 0)
{
double growth = growth + diameter;

System.out.printf("Increase: %.0f", );
System.out.println();


System.out.printf("Increase: %.0f",);
System.out.println();
}
}

Explanation / Answer

import java.util.Scanner;
class Balloon
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Diameter: ");
double diameter = in.nextDouble();
double growth=1;
  
int c=0;
while (c<10)
{
double vol=diameter*diameter*diameter*3.14/6;
diameter = growth + diameter;
System.out.printf("Increase in diameter: %.0f",growth);
System.out.println("New Diameter "+ diameter);

double growthvol=diameter*diameter*diameter*3.14/6;
  
System.out.printf("Increase in volume: %.0f",growthvol-vol);
System.out.println("New Volume "+growthvol);
c++;
}
}
}

================================================

What you have written code was little bit wrong so i have modified to run for 10 times.

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ javac Ballon.java
akshay@akshay-Inspiron-3537:~/Chegg$ java Balloon
Diameter: 12
Increase in diameter: 1New Diameter 13.0
Increase in volume: 245New Volume 1149.7633333333333
Increase in diameter: 1New Diameter 14.0
Increase in volume: 286New Volume 1436.0266666666666
Increase in diameter: 1New Diameter 15.0
Increase in volume: 330New Volume 1766.25
Increase in diameter: 1New Diameter 16.0
Increase in volume: 377New Volume 2143.5733333333333
Increase in diameter: 1New Diameter 17.0
Increase in volume: 428New Volume 2571.1366666666668
Increase in diameter: 1New Diameter 18.0
Increase in volume: 481New Volume 3052.08
Increase in diameter: 1New Diameter 19.0
Increase in volume: 537New Volume 3589.5433333333335
Increase in diameter: 1New Diameter 20.0
Increase in volume: 597New Volume 4186.666666666667
Increase in diameter: 1New Diameter 21.0
Increase in volume: 660New Volume 4846.59
Increase in diameter: 1New Diameter 22.0
Increase in volume: 726New Volume 5572.453333333334

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote