Question: Revise the Java program of Section 14.4.5 to use EOFException to detect the end of the input. Section 14.4.5 Following is the Java program with

Revise the Java program of Section 14.4.5 to use EOFException to detect the end of the input.


Section 14.4.5

Following is the Java program with the capabilities of the C++ program in Section 14.3.5:

throw new NegativeInputException (); index = newGrade / 10; try { freq[index]

++; } //** end of inner try clause catch (ArrayIndexOutOfBoundsException e) {


The exception for a negative input, NegativeInputException, is defined in the program. Its constructor displays a message when an object of the class is created. Its handler produces the output of the method. ArrayIndexOutOf- BoundsException is a predefined unchecked exception that is thrown by the Java run-time system. In both of these cases, the handler does not include an object name in its parameter. In neither case would a name serve any purpose. Although all handlers get objects as parameters, they often are not useful.

throw new NegativeInputException (); index = newGrade / 10; try { freq[index] ++; } //** end of inner try clause catch (ArrayIndexOutOfBoundsException e) { if (newGrade == 100) freq [9]++; else System.out.println ("Error - new grade: newGrade + " is out of range"); + } /** end of catch (ArrayIndex... } //** end of while (true) ... } //** end of outer try clause catch (NegativeInput Exception e) { System.out.println (" Limits for (index = 0; index < 10; index++) { limit_1 = 10 * index; limit_2 = limit_1 + 9; if (index == 9) limit_2 System.out.println ("" + limit_1 + Frequency "); 100; limit_2 + " + freq [index]); } //** end of for (index = 0; ... } //** end of catch (NegativeInputException } //** end of method buildDist %3D ...

Step by Step Solution

3.45 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Grade Distribution Input A list of integer values that represent grades followed by a negative numbe... View full answer

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 Concepts Of Programming Languages 10th Questions!