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

For this assignment, you will be creating a method which will be used later in t

ID: 3701082 • Letter: F

Question

For this assignment, you will be creating a method which will be used later in the project.

Write a method named AVERAGE:

Write a method named AVERAGE which calculates, and return, the AVERAGE of an array of integers. The method should receive as parameters, an array of integers and the filled size of the array.

Your method should assume that the array will contain some positive integers, filled in ascending order. This is a partially-filled array, where the number of items in the array may be less than the declared size of the array. The size parameter tells the method how many items are actually stored in the array.

The AVERAGE should be calculated as a double value.

Main program:

There is no main program required for this part. If you wish to test this method yourself outside of Mimir, then you would need to write a small main program which could be used to test your average method.

DONT USE BREAKS

CODE TO USE:

public class CalculateAverage {

/**
   * Calculates the average of the integers in array 'list'
   * @param list The array containing the integers for which to calculate the average
   * @param size The number of integers in array 'list'
   * @return The average of the integers in the array
   */
   public static double average(int [] list, int size) {
      
       return 0;
   }
}

Explanation / Answer

import java.util.*;
import java.lang.*;
import java.io.*;


public class CalculateAverage
{
        public static double average(int [] list, int size) {
            double avg=0.0; //Intializing the variable to store avergae
            int sum=0; //Variable to store sum of elements of array
            for(int i=0;i<size;i++) //looping through the array
            {
               sum=sum+list[i];
            }
             avg=(double)sum/size; //Takig the average of the list[] array
             return avg; //returning the value
     
    }

//For testing purpose included the main method also.
   public static void main (String[] args) throws java.lang.Exception //Testing the program
   {
       int [] list={1,2,3,5,7};
       double avg=average(list,list.length);
       System.out.println(avg); //Printing the value
       
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote