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

Hello, i need hlep with this question and the answer has to be in Java! Thanks I

ID: 3873793 • Letter: H

Question

Hello, i need hlep with this question and the answer has to be in Java! Thanks

In this assignment you are to implement and test each of the following methods

//returns the volume of a cube whose side length is sideLength

public static double boxVolume(double sideLength)

//returns the surface area of a cube whose side length is sideLength

public static double boxSurfaceArea(double sideLength)

//returns the volume of a sphere whose radius is radius

public static double ballVolume(radius)

//returns the surface area of a sphere whose radius is radius

public static double ballSurfaceArea(double radius)

//returns the volume of the largest sphere that will fit inside a box whose side length is //sideLength

public static double ballInBox(double sideLength)

//returns the volume of the largest cube that will fit inside a sphere whose radius is radius

public static double boxInBAll(double radius)

You must use the following main method in your program:

public static void main (String[] args) {

                       

                        // Initialize local variable for each parameter argument

                       

                            //sideLength for cube, and sphere//

                        double sideLength = 2.0;

                            // radius for ball

                        double radius = 6.0;

                       

                        // Define, invoke boxVolume method

                        System.out.println("The volume of a box with a side length of "

+ sideLength + " is " + boxVolume(sideLength));

                       

// Define , invoke boxSurfaceArea method

                       

System.out.println("The surface area of a box with a side length of "

+ sideLength + " is " + boxSurfaceArea(sideLength));

                       

// Define, invoke ballVolume method

                       

System.out.println("The volume of a ball with a radius of "

                        + radius + " is " + ballVolume(radius));

                       

// Define, invoke ballSurfaceArea method

                       

System.out.println("The surface area of a ball with a radius of "

                        + radius + " is " + ballSurfaceArea(radius));

                       

// Define, invoke ballInBox method

                       

System.out.println("The volume of the largest ball that" +

                        " can be placed inside a box with a side length of "

                        + sideLength + " is " + ballInBox(sideLength));

                       

// Define, invoke boxInBall method

                       

System.out.println("The volume of the largest box that"

                        + " can be placed inside a ball with a radius of "

                        + radius + " is " + boxInBall(radius));

                       

}

Explanation / Answer

Hi, I have implemented and tested the methods as you mentioned.

Formulas used:
Volume of box= sideLength*sideLength*sideLength
Surface area of box= 6 * (sideLength*sideLength)
Volume of sphere= 4/3 * Pi * radius * radius * radius
Surface area of sphere= 4 * Pi * radius * radius
Volume of the largest sphere that will fit inside a box whose side length is 'sideLength' = 4/3 * Pi * (sideLength/2) * (sideLength/2) * (sideLength/2)
Volume of the largest cube that will fit inside a sphere whose radius is 'radius'= (8*(R^3))/(3^1.5)

Below is the program:-

Calculations.java:

public class Calculations {


public static void main (String[] args) {
  
// Initialize local variable for each parameter argument
  
//sideLength for cube, and sphere//
double sideLength = 2.0;
// radius for ball
double radius = 6.0;
  
// Define, invoke boxVolume method
System.out.println("The volume of a box with a side length of "
+ sideLength + " is " + boxVolume(sideLength));
  
// Define , invoke boxSurfaceArea method
  
System.out.println("The surface area of a box with a side length of "
+ sideLength + " is " + boxSurfaceArea(sideLength));
  
// Define, invoke ballVolume method
  
System.out.println("The volume of a ball with a radius of "
+ radius + " is " + ballVolume(radius));
  
// Define, invoke ballSurfaceArea method
  
System.out.println("The surface area of a ball with a radius of "
+ radius + " is " + ballSurfaceArea(radius));
  
// Define, invoke ballInBox method
  
System.out.println("The volume of the largest ball that" +
" can be placed inside a box with a side length of "
+ sideLength + " is " + ballInBox(sideLength));
  
// Define, invoke boxInBall method
  
System.out.println("The volume of the largest box that"
+ " can be placed inside a ball with a radius of "
+ radius + " is " + boxInBall(radius));
  
}
//returns the volume of a cube whose side length is sideLength

public static double boxVolume(double sideLength){
return sideLength*sideLength*sideLength;
}

//returns the surface area of a cube whose side length is sideLength

public static double boxSurfaceArea(double sideLength){
return 6 * sideLength * sideLength;
}

//returns the volume of a sphere whose radius is radius

public static double ballVolume(double radius){
return ( 4* Math.PI * Math.pow(radius,3))/3 ;
}

//returns the surface area of a sphere whose radius is radius

public static double ballSurfaceArea(double radius){
return 4 * Math.PI * radius * radius;
}

//returns the volume of the largest sphere that will fit inside a box whose side length is //sideLength

public static double ballInBox(double sideLength){
double radiusOfSphere=sideLength/2;
return ballVolume(radiusOfSphere);
}

//returns the volume of the largest cube that will fit inside a sphere whose radius is radius

public static double boxInBall(double radius){
return boxVolume((2*radius)/(Math.sqrt(3)));
}
}


Sample run:
The volume of a box with a side length of 2.0 is 8.0
The surface area of a box with a side length of 2.0 is 24.0
The volume of a ball with a radius of 6.0 is 904.7786842338604
The surface area of a ball with a radius of 6.0 is 452.3893421169302
The volume of the largest ball that can be placed inside a box with a side length of 2.0 is 4.1887902047863905
The volume of the largest box that can be placed inside a ball with a radius of 6.0 is 332.5537550532245

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote