Instructor: Todd Dole
This lab will help you understand how to refactor your code by moving the main method into a separate class, while keeping the methods in MathOperations as static. This will allow you to call the methods directly without needing to create an object of MathOperations.
In the previous lab, you wrote a class MathOperations that contained static methods such as add, subtract, multiply, divide, fahrenheitToCelsius, and calculateCircleArea. Now, you will refactor your code by moving the main method into a separate class called MathOperationsApp.
MathOperationsApp in a separate file (e.g., MathOperationsApp.java).main method into the MathOperationsApp class. The MathOperations class should no longer contain the main method.MathOperations remain static. This way, in MathOperationsApp, you can call the methods directly from the class without creating an instance of MathOperations.MathOperationsApp class, call the methods from MathOperations directly. For example:
MathOperations.add(5, 3);MathOperations.fahrenheitToCelsius(100);Here’s an example of what the beginning of your MathOperationsApp class might look like:
public class MathOperationsApp {
public static void main(String[] args) {
// Basic math operations
int sum = MathOperations.add(5, 3);
...
}
}
Math Operations:
Addition: 5 + 3 = 8
Subtraction: 10 - 4 = 6
Multiplication: 7 * 6 = 42
Division: 9 / 3 = 3.0
Enter a temperature in Fahrenheit: 100
100.0 Fahrenheit is 37.77777777777778 Celsius.
Enter the radius of the circle: 5
The area of the circle with radius 5 is 78.53981633974483
Maximum of 3 numbers: 9, 15, 7 = 15
Submit both MathOperations.java and MathOperationsApp.java via Canvas by the due date. Ensure that both classes compile and run correctly, and be sure to test your code with various inputs.