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 TestMathOperations
.
TestMathOperations
in a separate file (e.g., TestMathOperations.java
).main
method into the TestMathOperations
class. The MathOperations
class should no longer contain the main
method.MathOperations
remain static. This way, in TestMathOperations
, you can call the methods directly from the class without creating an instance of MathOperations
.TestMathOperations
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 TestMathOperations
class might look like:
public class TestMathOperations { 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 TestMathOperations.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.