Question: I am attempting to add random integers to an ArrayList. After that, I would like to be able to get the sum, minimum number in

I am attempting to add random integers to an ArrayList. After that, I would like to be able to get the sum, minimum number in the ArrayList, the maximum number in the ArrayList, and also the average. I would then like to print all of that at the end.

import java.util.Random; import java.util.ArrayList; import java.util.Iterator; /** * Class for Lab * * @author S * @version 09.29.2017 */ public class Lab { // an integer constant field that defines the size of the array public static final int SIZE = 10; //an integer constant that defines the range of values to put into the array public static final int RANGE = 100000; //integer arraylist private ArrayList myArray; // random generator - to be used for choosing random numbers private Random randomGenerator; /** * Constructor for objects of class Lab */ public Lab() { // create new arraylist ArrayList myArray = new ArrayList(); } /** * This is the main method that will run the program when completed */ public static void main (String args[]) { Lab lab = new Lab(); lab.testMethods(); } /** * fill the array with integers between 0-10000 * @args the size of the arraylist */ public void fillArray() { // create a new random number generator randomGenerator = new Random(); for (int i = 0; i it = myArray.iterator(); int sum = 0; int i; for(i = 1; i < myArray.size(); i++) { sum += myArray.get(i); } return sum; } /** * get the average of the random numbers in the arraylist * @return avg returns average of all random numbers chosen */ public int getAvg() { int avg = 0; int sum = 0; for (int list : myArray) { sum = sum + list; } avg = sum/SIZE; return avg; } /** * print the value in each index */ public void printContents() { for (int index = 0; index 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!