Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Oracle Fusion Applications Installation And Administration

Authors: Tushar Thakker

1st Edition

1484209834, 9781484209837

More Books

Students also viewed these Databases questions