Ok. Here is working code. I just modified your code. According to Naming standard, you should use Class name like 'Try1' 'Try2'. And you should immediately throw exception if you don't wanna accept negative value. But according to your code, here it is.
In try2 class,
public try2(ArrayList<Integer> test) {
for (int x = 0; x <= test.size()-1; x++) {
try {
if (test.get(x) < 0 || test.get(x) > 100) {
throw new IllegalArgumentException();
} else {
this.userInput = test;
}
} catch (IllegalArgumentException ex) {
JOptionPane.showMessageDialog(null, " NO NEGETIVES ALLOWED ");
}
}
}
In try1 class,
public static void main(String[] args) {
testnum =
Integer.parseInt(JOptionPane.showInputDialog(null,
"Please Enter The Amount Of Test To Be Calculated Below "));
classes();
}
public static void classes() {
int userInput = 0;
if (userInput == JOptionPane.YES_OPTION) {
user = new ArrayList<Integer>();
for (int count = 1; count <= testnum; count++) {
String userInputString =
JOptionPane.showInputDialog(null, " PLEASE ENTER ALL THE FOLLOWING TEST GRADES TO CALCULATE ");
int value = Integer.parseInt(userInputString);
user.add(value);
}
if (userInput == JOptionPane.NO_OPTION) {
testing.setAvg();
JOptionPane.showMessageDialog(null, "You average is" + (testing.getAvg()));
}
new try2(user);
}
}
I only updated the codes I modified. You need to modify as you need.