Question: Modify the TestScores class created ito be serializable. a) Write a program that creates an array of eight TestScore objects and serialize these objects. b)

Modify the TestScores class created ito be serializable.

a) Write a program that creates an array of eight TestScore objects and serialize these objects. b) Similarly, write another program that deserializes the objects from the file

import java.util.Scanner; public class TestScores { int testScores[]; public TestScores(int[] testScores) throws IllegalArgumentException { for(int i=0;i

if(testScores[i]<0 || testscores[i]>100) { try { throw new InvalidTestScore("Score in the array is negative or greater than 100"); } catch (InvalidTestScore invalidTestScore) { invalidTestScore.printStackTrace(); } } }

this.testScores = testScores; } public double averageTestScore() { int sum =0; double average; for(int i=0;i

class InvalidTestScore extends Throwable { public InvalidTestScore(String s) { System.out.println(s); } } class Driver { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int totalTestScores; try { System.out.print("Enter total number of Test Scores: "); totalTestScores =sc.nextInt(); int[] testScores = new int[totalTestScores]; for (int i = 0; i < testScores.length; i++) { System.out.print("Please enter Test Scores: "); testScores[i] = sc.nextInt(); } TestScores testScoresObj = new TestScores(testScores); System.out.println(testScoresObj.averageTestScore());

} catch (IllegalArgumentException e) { System.out.println("Test scores must have a value less than 100 and greater than 0."); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!