Question: Keep hitting error with the arraylist, dont know how can I fix it. And how to I impliment catch to the program? Thank you Code:

 Keep hitting error with the arraylist, dont know how can I Keep hitting error with the arraylist, dont know how can I fix it. And how to I impliment catch to the program? Thank you Code: package AverageProblem; import java.util.ArrayList; import java.util.Scanner; /** * Created by EdwardLai on 2/26/17. * * Write a program which calculates the average of N integers. The program should prompt the user to enter * the value of N. Afterwards the user must enter all N of the integers. If the user enters a non- positive * value for any of the integers, an exception should be thrown (and caught) with the message N must be positive. If there is any exception as the user is entering the N numbers, an error message should be displayed and the user prompted to enter the number again. Save your solution in Average.java. */ public class Average { private static int intergerNum; private static int loopcount=0; private static ArrayList array = new ArrayList(); static Scanner scanner= new Scanner(System.in); public static void main (String[] args) { System.out.println("This is a interger average calculator "); while(intergerNum != 9999) { System.out.println("Please input a positive interger: "); intergerNum = scanner.nextInt(); if(intergerNum != 9999) { checkPositive(intergerNum); array.add(loopcount,intergerNum); loopcount++; } } double sum = 0.0; for(int i : array ) { sum+=array.get(i); } System.out.println("The average is: "+ (double)(intergerNum/loopcount)); } public static void checkPositive(int num) { if (num   write a program which calculates the average of N integers. The program should prompt the user to enter the value of N. Afterwards the user must enter all N of the integers If the user enters a non- positive value for an of the integers, an exception should be thrown (and caught with the message "N must be positive." If there is any exception as the user is entering the N numbers, an error message should be displayed and the user prompted to enter the number again

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!