public class TestScores { private int[] scores; public TestScores(int[] arr) { this.scores = new int[arr.length]; for (int i = 0; i < arr.length; i++){ if (arr[i] > 100 || arr[i] < 0) throw new IllegalArgumentException("Invalid argument: " + arr[i]); else this.scores[i] = arr[i]; } } public double getAverage(){ double sum = 0; for (int i = 0; i < this.scores.length; i++) sum += scores[i]; return sum / scores.length; } public static void main(String[] args) { int[] arr = {-8,2,3,4,5,5,600}; try { TestScores ts = new TestScores(arr); System.out.println(ts.getAverage()); } catch (IllegalArgumentException e){ System.out.println(e.getMessage()); } } }