2. Write an exception class named InvalidTestScores. Rewrite the class written in Problem 1 to throw this new exception, InvalidTestScores, if any value in the array is an invalid number.
This is JAVA program
import java.util.Scanner;
class Driver {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int totalTestScores;
try {
System.out.println("Enter total number of Test Scores:");
totalTestScores = sc.nextInt();
int[] testScores = new int[totalTestScores];
System.out.println("Please enter Test Scores:");
for (int i = 0; i < testScores.length; i++) {
testScores[i] = sc.nextInt();
}
TestScores testScoresObj = new TestScores(testScores);
System.out.println("Average Test Score is : " + testScoresObj.averageTestScore());
} catch (InvalidTestScores e) {
System.out.println("Test scores must have a value less than 100 and greater than 0.");
}
}
}
class TestScores {
private int testScores[];
public TestScores(int[] testScores) throws InvalidTestScores {
for (int i = 0; i < testScores.length; i++) {
//If any of input value contain less than zero
//or greater than 100 throw IllegalArgumentException
if (testScores[i] < 0 || testScores[i] > 100) {
throw new InvalidTestScores();
}
}
//If everything went fine then assign testScores to class testScores variable
this.testScores = testScores;
}
public double averageTestScore() {
int sum = 0;
double average;
for (int i = 0; i < testScores.length; i++) {
sum = sum + testScores[i];
}
average = (double) sum / testScores.length;
return average;
}
}
class InvalidTestScores extends Exception {
public InvalidTestScores() {
}
public InvalidTestScores(String message) {
super(message);
}
}


2. Write an exception class named InvalidTestScores. Rewrite the class written in Problem 1 to throw...
JAVA PROG HW Problem 1 1. In the src −→ edu.neiu.p2 directory, create a package named problem1. 2. Create a Java class named StringParser with the following: ApublicstaticmethodnamedfindIntegerthattakesaStringandtwocharvariables as parameters (in that order) and does not return anything. The method should find and print the integer value that is located in between the two characters. You can assume that the second char parameter will always follow the firstchar parameter. However, you cannot assume that the parameters will be different from...
Write a class named TestScores. The class constructor should accept an array test scores as its argument. The class should a method that returns the average of the test scores. If any test score is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate this with an array of five items. This is JAVA program.
Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program (create a Driver class in the same file). The program should ask the user to input the number of test scores to be...
C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...
Please use Java only. Write a class, ZeroException, which is an Exception, and is used to signal that something is zero when it shouldn't be. -- Not needed Write the class ArrayManipulator which creates an array and provides several methods to manipulate values taken from an array. --needed ZeroException Task: -- Not needed Exceptions are used to signal many types of problems in a program. We can write our own as well to describe specific exceptional conditions which may arise....
IN JAVA: Write a class, ZeroException, which is an Exception, and is used to signal that something is zero when it shouldn't be. Write the class ArrayManipulator which creates an array and provides several methods to manipulate values taken from an array. ZeroException Task: Exceptions are used to signal many types of problems in a program. We can write our own as well to describe specific exceptional conditions which may arise. The advantage of doing so is that when exceptions...
Problem 2 1. In the src → edu.neiu.p2 directory, create a package named problem1. 2. Create a Java class named Complement with the following: • A public static method named onesComplement that takes a String as a parameter and returns a String that is the 1’s complement of the parameter. • If the String is not a valid binary number (i.e. only has 0s and 1s), you should throw an IllegalArgumentException with the message "Not a valid binary number". •...
a) Create an abstract class Student. The class contains fields for student Id number, name, and tuition. Includes a constructor that requires parameters for the ID number and name. Include get and set method for each field; setTuition() method is abstract. b) The Student class should throw an exception named InvalidNameException when it receives an invalid student name (student name is invalid if it contains digits). c) Create three student subclasses named UndergradStudent, GradeStudent, and StudentAtLarge, each with a unique...
JAVA Problem Description: For this assignment, you will be writing your own exception class and you will handle run-time exceptions resulting from one particular input situation. Specifics: 1) Design and implement a program that has an exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it. 2) In the main driver of the program (call this class MyExceptionTest), read strings from the user until the user enters “DONE”. If a...
import java.util.Scanner; import java.io.File; public class Exception2 { public static void main(String[] args) { int total = 0; int num = 0; File myFile = null; Scanner inputFile = null; myFile = new File("inFile.txt"); inputFile = new Scanner(myFile); while (inputFile.hasNext()) { num = inputFile.nextInt(); total += num; } System.out.println("The total value is " + total); } } /* In the first program, the Scanner may throw an...