Reference no: EM132380746
Introduction
This assignment practices Java skills on:
• how to handle and throw exceptions
• how to write an exception class
Task
Write a class named TestScores. The class constructor should accept a double array of test scores as its argument. The class should have a method called getAverage that returns the average of the test scores.
Next, write an exception class named InvalidTestScore.
Back to the class TestScores, if any test score in the array is negative or greater than 100, the class should throw an InvalidTestScore exception.
Demonstrate your TestScores and InvalidTestScore classes by using this demo program, TestScoresDemo.java (right click to save a copy of this file).
Example
Below is an example of how input and output of your program might look like:
To compile your code, use the command:
%javac InvalidTestScore.java
%javac TestScores.java
%javac TestScoresDemo.java
To execute your compiled program, use the command:
% java TestScoresDemo
Invalid score found.
Element: 3 Invalid Score: 101.0
The average of the good scores is 90.24
Submission
Submit your Java source files (TestScores.java and InvalidTestScore.java) using the submit program on Turing. We will use our TestScoresDemo.java to test your program. Ensure you compile and test your code using test values of your own creation as part of your submission script, demonstrating that your program compiles without errors and works as expected.