need help with illegalArgumentException
hi, every
i'm new to java.
i need u to help to grade my program:
Write a class named TestScores. The class contructor should accept an array of test scores as its argument. the class should have a method that return the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw as IllegalArgumentException.Demonstrate the class in a program.
1- Did i program right so far for my first class?
2-I dont know where to put this part :If any test score in the array is negative or greater than 100.
here is my first class:
publicclass TestScores
{
privatedouble[] testScores;
public TestScores(double[] ts)
{
testScores = ts;
}
publicdouble getAverage()
{double total =0;
double average= 0;
try
{
for (int i =0; i<testScores.length; i++)
total += testScores[i];
average = total/testScores.length;
}
catch(IllegalArgumentException e)
{
System.out.println(" Bad number format.");
}
return average;
}
>

