Hi Everyone,

Days that I'm on that problem. I have to calculate a substitution score.

Below my code:

public void calcSubstitutionScore()   
   {
      substitutionScore = (average + examMark) /2; 
   }

I previously created the method average, and I try to add to it examMark divide by two, which is suppose to give the substitutionscore. I get a syntax error:

operator + cannot be applied to java.util.List<Java.lang.Integer>,int

I have problem how to deal with Integer:'(

One of your variables is a List, so natuarally you cannot add ("+") a list to an integer

One of your variables is a List, so natuarally you cannot add ("+") a list to an integer

Thanks JavaAddict for your reply:)

I change my code to go around that problem, I get no syntax error but instead I get a semantic error:(

public void calcSubstitutionScore()   
   {
      List<Integer> subScore = new ArrayList<Integer>();
      int size = tmaMarks.size();
      List<Integer> average = new ArrayList<Integer>();
      getTmaMarks();
      getExamMark();
      int tmaMarks = (size/4);
      substitutionScore = (subScore.get(tmaMarks) + subScore.get(examMark))/2; 
   }

Here is the semantic error:

Exception: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0

:?:

Again you cannot access the elements of a list without checking their size. When you are calling this:
subScore.get()
you need to make sure that the argument is between 0 and size()
According to the error your list is empty

Again you cannot access the elements of a list without checking their size. When you are calling this:
subScore.get()
you need to make sure that the argument is between 0 and size()
According to the error your list is empty

I just show below how I'm suppose to test the method calcSubstitutionScore() in the displaypanel:

Student n = new Student("Becca");// line 1
Integer[] numberArray = {5, 6, 7, 8};// line 2
n.setTmaMarks(Arrays.asList(numberArray));// line 3
n.setExamMark(61);// line 4
n.calcSubstitutionScore();// line 5


I'm lost, I don't see how to check the size of the list, I thought line 2 3 and 4 gave check the size.

In your calcSubstitutionScore method you create new lists. You don't use the ones with the scores

In your calcSubstitutionScore method you create new lists. You don't use the ones with the scores

I'm still working on that problem. I can't figure it out, would it be possible to give me a similar example, or even would you know where can I look for a tutorial on the subject.:)

I'm still working on that problem. I can't figure it out, would it be possible to give me a similar example, or even would you know where can I look for a tutorial on the subject.:)

Well I will repeat myself. In the calcSubstitutionScore you create new List: List<Integer> subScore = new ArrayList<Integer>() that has no elements inside. And then you are trying to access it, so naturally this: subScore.get(tmaMarks) will not work since it has no elements.
Shouldn't you be using the private subScore List after you enter some values to it, instead of creating a new one with no values?

Secondly, did the average method had an argument or you added it. Because I believe that it should calculate the average value of one the lists declared in the class, but again I don't know what it is supposed to do.

Thanks javaAddict for your help, I finally got it:) :icon_idea: