I created a class student, with 2 results for their exams. The first is Terminal marks and second is Exam marks. I created a method called average.
Here is the code for this method:
Code:
/ **
* Calculates average of a list of integers
* /
public double average (List <integer> list)
{
double sum = 0.0;
for (int i = 0; i <list.size () i = i +1)
{
sum = sum + list.get (i);
}
return sum/4;
}
This method works great, when I type in display pane:
Integer[] numberArray = {75, 59, 0, 70};
Student.average (Arrays.asList (numberArray));
51 is the result which is correct.
My problem is to create the following method. I have to calculate the average of Terminal over Exam marks divided by 2. For example 51 + 64 / 2, which gives me the result of substitution of 57%. Here is my code:
Code:
/ **
* Calculates and sets the substitutionScore of the receiver
* /
public void calcSubstitutionScore ()
{
for (int aScore:scores)
{
this. results. put (aScore, new HashSet<String> ( ) ) ;
}
for (String average: students. keySet ())
{
for (String graded: this. results. get (average))
{
this. results. get (graded). add (average) / 2;
}
}
}
Bookmarks