public class Average
{
    private double [] Score;
    int index;

    public Average(double [] s)
    {
        Score = new double[s.length];



        for(index=0; index<s.length; index++)
        {

            if(Score[index]>100 && Score[index]<0)
              Score[index]=s[index];
         }


      }









    public double getAverage()
    {
        double total=0.0;
        double average = 0.0;
        for(double value: Score)
        total+=value;
         average= Score.length/total;
         return average;

    }
}

the actual assingment is to write an IllegalArgumentException method inoder to prevent the program from accepting negative or score grater than 100

Recommended Answers

All 3 Replies

Okay? And what have tried?

by try catch block not working

In your class the "s" input is the one that has the values not the Score. I mean it is the "s" that you pass as parameter, then you put values from s to Score. Why on earth are you checking the values of Score if you put the values "s" in it after the checking?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.