CSCI-1320 Lab: Moving the Main Method

Instructor: Todd Dole

Purpose Statement

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.

Instructions

Part 1: Refactor Your Code

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.

Steps to Follow

Part 2: Example Code

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);
        ...
    }
}
            

Example Output

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
            

Part 3: Submission

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.