Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assign to maxSum the max of (numA, numB) PLUS the max of (numY, numZ). Use just

ID: 3685743 • Letter: A

Question

Assign to maxSum the max of (numA, numB) PLUS the max of (numY, numZ). Use just one statement. Hint: Call findMax() twice in an expression.

import java.util.Scanner;

public class SumOfMax {

public static double findMax(double num1, double num2) {

double maxVal = 0.0;

// Note: if-else statements need not be understood to

// complete this activity

if (num1 > num2) { // if num1 is greater than num2,

maxVal = num1; // then num1 is the maxVal.

}

else { // Otherwise,

maxVal = num2; // num2 is the maxVal.

}

return maxVal;

}

public static void main(String [] args) {

double numA = 5.0;

double numB = 10.0;

double numY = 3.0;

double numZ = 7.0;

double maxSum = 0.0;

/* Your solution goes here */

System.out.print("maxSum is: " + maxSum);

return;

}

}

Explanation / Answer

public class SumOfMax {

   public static double findMax(double num1, double num2) {

       double maxVal = 0.0;

       // Note: if-else statements need not be understood to

       // complete this activity

       if (num1 > num2) { // if num1 is greater than num2,

           maxVal = num1; // then num1 is the maxVal.

       }

       else { // Otherwise,

           maxVal = num2; // num2 is the maxVal.

       }

       return maxVal;

   }

   public static void main(String[] args) {

       double numA = 5.0;

       double numB = 10.0;

       double numY = 3.0;

       double numZ = 7.0;

       double maxSum = 0.0;

       /* Your solution goes here */
      
       maxSum = findMax(numA, numB); // first call of findMax
      
       maxSum = maxSum + findMax(numY, numZ); // second call

       System.out.print("maxSum is: " + maxSum);

       return;

   }

}

/*

Output:

maxSum is: 17.0

*/