The volume V of a hollow sphere with inner radius r and outer radius R is: V = 4
ID: 3663959 • Letter: T
Question
The volume V of a hollow sphere with inner radius r and outer radius R is: V = 4/3pi(R3 -r3) Suppose you have one hollow sphere with inner and outer radii 0.75m and 1.2m, and a second with inner and outer radii 1.6ft and 2.1ft, and a third sphere with an inner radius of 3.1 yards and an outer radius of 3.4 yards. Your goal is to keep increasing the size of the spheres until the sum of the material needed to build all three spheres is greater than 50 cubic meters. Increase both the inner and the outer radii by 0.1 meters repeatedly (using a loop) until the sum of the volume of material for all three spheres is greater than 50 cubic meters. Print out the largest and smallest individual final volumes. Your answer should be in cubic meters. Format your answer to two decimal places. Answers not using a loop will receive no credit.Explanation / Answer
/**The java program MaxVolume that finds the largest ,smallest
* and middle of three hollow sphere volumes of max is less than
* 50 cubic meters. Print largest, smallest and middle.*/
//MaxVolume.java
public class MaxVolume
{
public static void main(String[] args)
{
//declare double variables
double v1=0;
double v2=0;
double v3=0;
double maxv=0;
//a double variable of increment =0.1
double increment=0.1;
double v1innerRadii=0.75;
double v1outerRadii=1.2;
//Covert feet to meters
double v2innerRadii=1.6*0.3048;
double v2outerRadii=2.1*0.3048;
//Covert yard to meters
double v3innerRadii=3.1*0.9144;
double v3outerRadii=3.4*0.9144;
//Run the while loop until max volume is less than 50
while(maxv<50)
{
//find three volumes with an increment of 0.1
v1=findVolume(v1innerRadii,v1outerRadii,increment);
v2=findVolume(v2innerRadii,v2outerRadii,increment);
v3=findVolume(v3innerRadii,v3outerRadii,increment);
//add three volumes
maxv=v1+v2+v3;
//incrment the 0.1
increment=increment+0.1;
}
//sort three volumes ,print largest,smallest and middle
if(v1>v2 && v1>v3)
{
System.out.printf("Largest %.2f ",v1);
if(v2>v3)
{
System.out.printf("Smallest %.2f ",v3);
System.out.printf("Middle %.2f ",v2);
}
else
{
System.out.printf("Smallest %.2f ",v2);
System.out.printf("Middle %.2f ",v3);
}
}
else if(v2>v1 && v2>v3)
{
System.out.printf("Largest %.2f ",v2);
if(v1>v3)
{
System.out.printf("Smallest %.2f ",v3);
System.out.printf("Middle %.2f ",v1);
}
else
{
System.out.printf("Smallest %.2f ",v1);
System.out.printf("Middle %.2f ",v3);
}
}
else
{
System.out.printf("Largest %.2f ",v3);
if(v1>v2)
{
System.out.printf("Smallest %.2f ",v2);
System.out.printf("Middle %.2f ",v1);
}
else
{
System.out.printf("Smallest %.2f ",v1);
System.out.printf("Middle %.2f ",v2);
}
}
}//end of main metod
/*The method findVolume that takes inner ,outer and increment as input
* arguments and returns the volume of the hollow sphere and returs
* the volume*/
private static double findVolume(double innerraddi,double outerraddi,
double increment)
{
return ((4.0/3.0)*(Math.PI))
*(Math.pow((outerraddi+increment), 3.0)-Math.pow((innerraddi+increment), 3.0));
}
}
---------------------------------------------------------------------------------------------------------------------------
Sample output:
Largest 39.21
Smallest 1.78
Middle 10.79
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.