Question: Write an exception class named InvalidTestScore. Modify the TestScores class you wrote in Programming Challenge 1 so that it throws an InvalidTestScore exception if any
Write an exception class named InvalidTestScore. Modify the TestScores class you wrote in Programming Challenge so that it throws an InvalidTestScore exception if any of the test scores in the array are invalid.
Please write the code as simple as possible with nonadvanced techniques. Please leave detailed comments for everything. Thank you!!
Here is my code for Program Challenge
public class TestScores
Create score array
private double score;
Constructor to initialize values
public TestScoresdouble scores
this.scorescores;
Method to calculate average
public double avg
double sum ;
forint x; x && scorex
sumscorex;
else
throw IllegalArgumentExeption
throw new IllegalArgumentException;
Get average from sum and return avg
double avg sumscorelength;
return avg;
public class TestScoresDEMO
public static void mainString args
Array a initialized with test scores
double a;
Object created and array a is passed
TestScores obj new TestScoresa;
Average method called for obj
System.out.printlnaverage score for obj:objavg;
Array b initialized with bad values
double b;
Object created and array b is passed
TestScores obj new TestScoresb;
Average method called for obj
System.out.printlnaverage score for obj:objavg;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
