This commit is contained in:
2025-04-27 23:18:34 -05:00
parent a4c38c3317
commit a51b301cc7
2 changed files with 24 additions and 0 deletions

View File

@@ -1,3 +1,7 @@
/**
* InvalidTestScore is a custom exception for the TestScores class. It is thrown when a score does not fall in valid
* range
*/
public class InvalidTestScore extends IllegalArgumentException {
public InvalidTestScore(String message) {
super(message);

View File

@@ -32,6 +32,26 @@ public class Main {
}
public static void main(String[] args) {
// Main for q1
// Test are 2 test score arrays that will throw the exception when we try to get the averages
int[] arr1 = {90, 91, -2, 21, 99};
int[] arr2 = {90, 91, 101, 21, 99};
try{
TestScores t1 = new TestScores(arr1);
System.out.println(t1.getAverage());
}
catch (Exception e) {
System.out.println(e.getMessage());
}
////
try{
TestScores t2 = new TestScores(arr2);
System.out.println(t2.getAverage());
}
catch (Exception e) {
System.out.println(e.getMessage());
}
// Main for Q2