Utility methods

  1. Create a class called Utilities (stored in Utilities.java)
  2. Create the following methods:
    1. A method that prints the kinetic energy (E) of an object given its mass (E=mc2).
      1. c is the speed of light, which is constant. You can use 299,792,458 metres per second. Use the final keyword to represent this constant (using final on a variable prevents people from assigning it a new value after initialization). The constant should be in all caps, e.g., SPEED_OF_LIGHT.
      2. The speed of light should not be a parameter to the method because its value should not change between method invocations.
    2. A method that prints the area of a circle given its radius.
      1. You may use the equation Πr2.
      2. Π should not be a parameter to your method (it never changes).
      3. Use the constant representing Π in the Java Math class.
    3. A method that prints the area of a rectangle given its length and width.
    4. A main method that tests the above three methods. You may use hard-coded values as arguments to the methods.
  3. Upload your Utilities.java file only.

This material was created by Raffi Khatchadourian and published freely under a Creative Commons Attribution 4.0 license.