The objective of this assignment is for the student to create a Java class that has several static functions. The student will get experience writing simple functions, with arguments and return values.

We have covered data types, operators (math and assignment), if() statements, loops, and functions. It's time to work with some of these features of the Java programming language. You can find the required formulas on Wikipedia or in any math textbook that you choose.

Write a Java class. The class name must be ShapeMetrics, which of course implies the source code file name ShapeMetrics.java. Provide the following functions:

  • getAreaOfRectangle(), with two float arguments, width and height, returning a float value which is the area of the rectangle with that width and height.
  • getDiagonalOfRectangle(), with two float arguments, width and height, returning a float value which is the length of the diagonal line which bisects the rectangle.
  • getSpaceDiagonalOfRegularCuboid(), with three float arguments, width, height, and depth, where each argument represents the length of a side of a cuboid, returning a float value that is length of the space diagonal.
  • getVolumeOfSphere(), with one float argument, the radius of a sphere, returning a float value that is the volume of the sphere that is described by the argument.
  • getSurfaceAreaOfSphere(), with one float argument, the radius of a sphere, returning a float value that is the surface area of the sphere that is described by the argument.

All functions must be public and static. Do not put a main() function or any println() statements in your class.

Common pitfalls:

  • Using the wrong name for the class or the functions. Remember, case counts.
  • Returning the wrong data type.
  • Failure to follow instructions.

Here is sample output from my solution. You dont have to get the exact same numbers, but you should get pretty close.

The area of the rectangle with width 3.7 and height 2.1 is: 7.77.
The diagonal of the rectangle with width 3.7 and height 2.1 is: 4.25.
The space diagonal of the cuboid with width 3.7 and height 2.1 and depth 8.8 is: 9.77
The volume of the sphere with radius 3.3 is: 150.53
The surface area of the sphere with radius 3.3 is: 136.85
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.