- Create a class called
Utilities
(stored inUtilities.java
) - Create the following methods:
- A method that prints the kinetic energy (E) of an object given its mass (E=mc2).
- 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
. - The speed of light should not be a parameter to the method because its value should not change between method invocations.
- 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.,
- A method that prints the area of a circle given its radius.
- You may use the equation Πr2.
- Π should not be a parameter to your method (it never changes).
- Use the constant representing Π in the Java Math class.
- A method that prints the area of a rectangle given its length and width.
- A main method that tests the above three methods. You may use hard-coded values as arguments to the methods.
- A method that prints the kinetic energy (E) of an object given its mass (E=mc2).
- Upload your
Utilities.java
file only.
This material was created by Raffi Khatchadourian and published freely under a Creative Commons Attribution 4.0 license.