1) Complete the last four methods of the partially-implemented program below. Submit your .java file Week 1 Homework via Blackboard before the beginning of lab on Friday (see the Blackboard deadline). You will be required to demo your program during lab.
/**
* @author hornick
* This class/program creates arrays and ArrayLists, fills them with values, and computes the averages of the values
*/
public class CollectionApp {
/**
* @param args
*/
public static void main(String[] args) {
double numArray[] = null; // a primitive array that holds a collection of doubles
ArrayList<Double> numList = null; // a JCF collection class that holds a collection of Doubles
System.out.println("Enter a low and a high value: ");
Scanner kbd = new Scanner(System.in);
int low = kbd.nextInt();
int high = kbd.nextInt();
numArray = fillArray( low, high ); // create and fill the array
numList = fillArrayList( low, high ); // create and fill the ArrayList
double avg1 = getArrayAvg( numArray );
double avg2 = getArrayListAvg( numList );
System.out.println("Array avg=" + avg1 + ", ArrayList avg=" + avg2 );
}
/**
* This method allocates and fills an array with the values from the specified low to the specified high;
* for example, if low is -1 and high is 3, then the array will hold -1, 0, 1, 2, 3
* @param low - the lowest value in the array
* @param high - the highest value in the array
* @return - reference to the created non-empty array of doubles
*/
public static double[] fillArray( int low, int high ) {
// put your additional code here that allocates and fills the array
// return the reference to the new array
}
/**
* This method allocates and fills an ArrayList with the values from the specified low to the specified high values
* for example, if low is -1 and high is 3, then the ArrayList will hold -1, 0, 1, 2, 3
* @param low - the lowest value in the ArrayList
* @param high - the highest value in the ArrayList
* @return - reference to the created non-empty ArrayList of Doubles
*/
public static ArrayList<Double> fillArrayList( int low, int high ) {
// put your additional code here that allocates and fills the ArrayList
// return the reference to the new ArrayList
}
/**
* This method computes the average of the values in the specified array
* @param numArray - reference to an array of values, created elsewhere
* @return - the average of the values within the array
*/
public static double getArrayAvg( double numArray[] ) {
// put your additional code here that computes and returns the average
}
/**
* This method computes the average of the values in the specified ArrayList
* @param numList - reference to an ArrayList of values, created elsewhere
* @return - the average of the values within the ArrayList
*/
public static double getArrayListAvg( ArrayList<Double> numList ) {
// put your additional code here that computes and returns the average
}
}