Java and my following program, I need help in creatin an Exception class named InvalidScore. Modify my program so that it "throws" an InvalidScore Exception, when any of my test scores are not b/w 0 through 100.   //class AverageScores class AverageScores {                //array of scores declared                int scores[]=new int[100];                //constructor                public AverageScores(int[] scores) {                               super();                               //accepts an array of test scores                               this.scores = scores;                }                //method that returns the average of the test scores                double average()                {                               //declares variables of integer type                               int sum=0;                               int count=0;                               //obtain length of array                               int len = scores.length;                               //for loop                               for(int i=0;i100)                                              {                                                             //show a "DeniedException"                                                             System.out.println("DeniedException at index "+i+" and value "+scores[i]);                                                             //continue the loop                                                             continue;                                              }                                              //computed sum of the array                                              sum=sum+scores[i];                                              //increment count by 1                                              count++;                               }                               //determine the average                               double average=(double)sum/count;                               //return average                               return average;                } } //class test to Test the "AverageScores" class program public class test {                //main method                public static void main(String args[])                {                               //declared and initialize the array                               int scores[]= {61,72,-1,39,40,78,43,101,203,45,65};                               //created object of class AverageScores                               AverageScores as=new AverageScores(scores);                               //calling method average()                               double avg=as.average();                               //print average                               System.out.println("Average= "+avg);                }                }

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter11: Exception Handling
Section: Chapter Questions
Problem 2CP
icon
Related questions
Question

In Java and my following program, I need help in creatin an Exception class named InvalidScore. Modify my program so that it "throws" an InvalidScore Exception, when any of my test scores are not b/w 0 through 100.

 

//class AverageScores

class AverageScores {

               //array of scores declared

               int scores[]=new int[100];

               //constructor

               public AverageScores(int[] scores) {

                              super();

                              //accepts an array of test scores

                              this.scores = scores;

               }

               //method that returns the average of the test scores

               double average()

               {

                              //declares variables of integer type

                              int sum=0;

                              int count=0;

                              //obtain length of array

                              int len = scores.length;

                              //for loop

                              for(int i=0;i<len;i++)

                              {

                                             //if statement to check any test score in the array is negative or above 100

                                             if(scores[i]<0 || scores[i]>100)

                                             {

                                                            //show a "DeniedException"

                                                            System.out.println("DeniedException at index "+i+" and value "+scores[i]);

                                                            //continue the loop

                                                            continue;

                                             }

                                             //computed sum of the array

                                             sum=sum+scores[i];

                                             //increment count by 1

                                             count++;

                              }

                              //determine the average

                              double average=(double)sum/count;

                              //return average

                              return average;

               }

}

//class test to Test the "AverageScores" class program

public class test

{

               //main method

               public static void main(String args[])

               {

                              //declared and initialize the array

                              int scores[]= {61,72,-1,39,40,78,43,101,203,45,65};

                              //created object of class AverageScores

                              AverageScores as=new AverageScores(scores);

                              //calling method average()

                              double avg=as.average();

                              //print average

                              System.out.println("Average= "+avg);

               }

              

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning