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

JAVA Write a program with a main method and two other methods. 1.Main Method: -U

ID: 3814794 • Letter: J

Question

JAVA

Write a program with a main method and two other methods.

1.Main Method:

-User enters three numbers

-Print out all results

2.calcSum Method (first, second, third):

- Get three numbers as parameters

- if first is less than second, first = first * second ¥ if second is less than third, third = second * first

- Return the sum of these three numbers ¥ calcAvg Method (first, second, third):

- Get three numbers as an input ¥ Return the average of these three numbers as double value

Output:

Enter first number:3

Enter second number:5

Enter third number:7

The summation of all numbers: 95

The average of all numbers: 5.0

Explanation / Answer

package average;

import java.util.Scanner;
/**
*
* @author Naresh
*
*/
public class Summation {
   /**
   *
   * @param num1
   * @param num2
   * @param num3
   * @return
   */
   public static int calcSum(int num1, int num2, int num3){
       if(num1 < num2){
           num1 = num1*num2;
       }
       if(num2 < num3){
           num3 = num2 * num1;
       }
      
       return (num1 + num2 + num3);
      
   }
   /**
   *
   * @param num1
   * @param num2
   * @param num3
   * @return
   */
   public static double calcAvg(int num1, int num2, int num3){
       return (num1 + num2 + num3)/3;
   }

   public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
       System.out.println("Enter number 1 :");
       int num1 = input.nextInt();
       System.out.println("Enter number 2 :");
       int num2 = input.nextInt();
       System.out.println("Enter number 3 :");
       int num3 = input.nextInt();
       System.out.println("The summation of all numbers: "+calcSum(num1, num2, num3));
       System.out.println("The average of all numbers: "+Summation.calcAvg(num1,num2,num3));
      
   }

}