How to calculate substitution
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;
}
}
}
Re: How to calculate substitution
Why does not it function? What is the error message?
Re: How to calculate substitution
It gives me a lot of syntax errors. For example for the line:
this.results.get (graded). add (average)/2;
It makes me: not a statement.
For the line:
for (int aScore : scores)
It makes me: cannot find symbol - variable score
I have in a class called Student: private int substitutionScore; Having 2 methods:
Code:
/ **
* Sets the substitutionScore of the receiver to aScore
* /
private void setSubstitutionScore (int aScore)
{
this. substitutionScore = aScore;
}
/ **
* Returns the substitutionScore of the receiver
* /
public int getSubstitutionScore ()
{
return this. substitutionScore;
}
Re: How to calculate substitution
In Java the use of the terms subject to different rules of visibility. It is not enough that you sent in your head, and so the Java will work.
As a very simple example:
Code:
{// Block
{// Another block
int quantity; // I declare my variable here
quantity = 45 // good: the variable quantity is declared in the same block
Quantity = 45 // syntax error here: quantity is not EQUAL to Quantity in Java
}
quantity = 45 // syntax error here: quantity is not declared in this block.
}