Explore BrainMass

Explore BrainMass

    Overloaded Java Methods

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Write overloaded Java methods that return the difference of two parameters. Your methods should contain the logic to return the difference of the larger parameter ?smaller parameter, regardless of parameter order. Provide enough test code to ensure your methods are logically correct. The following table displays the required method parameter variations.

    Parm 1 Type Parm 2 Return type
    int int int
    double double double
    int double double
    double int double

    properly document your source code.

    Compile and run your program until it works and the output looks nice.

    © BrainMass Inc. brainmass.com October 9, 2019, 10:37 pm ad1c9bdddf

    Solution Preview

    Please see the attachment.

    // NumDiff.java

    public class NumDiff {
    // Case 1: Input int, int, return int
    int diff(int para1, int para2) {
    return Math.abs(para1 - para2);
    // We use abs function in Math to get the difference
    // Case 2: Input double, ...

    Solution Summary

    This solution contains a Java program that returns the difference of two parameters.