Hi Richard, Sorry for the long pause....
I'm using the java_class question type.
Here's an example of the behavior:
Question:
Write the class Ocean that has a toString() method returning new Fish().toString();
Expected Answer:
class Ocean
{
public String toString()
{
return new Fish().toString();
}
}
Support file: Fish.java looks like this:
class Fish
{
public String toString()
{
return "fish";
}
}
So the expected output from printing toString is 'fish'.
However, the Student's answer is:
class Ocean
{
public String toString()
{
return new Fish().toString();
}
}
//thinking they also needed to supply Fish!
class Fish
{
public String toString()
{
return "walrus"; //and coming up with their own behaviour
}
}
The test
Ocean o = new Ocean();
System.out.println(o.toString()); | fish
|
fails, as the output is 'walrus' instead of 'fish'.
I suppose it depends on the template to some extent, which generally looks like this:
{{ STUDENT_ANSWER | replace({'public class ': 'class '}) }}
public class __tester__ {
public static void main(String[] args) {
__tester__ main = new __tester__();
main.runTests();
}
public void runTests() {
{{ TEST.testcode }};
}
}
So it may be to do with the order in which the files are compiled. I'm suspecting:
1 javac Fish.java -> Fish.class
2. javac __tester__.java -> __tester__.class, Ocean.class, Fish.class, i.e. overwriting the original Fish.class
I don't actually know what order javac compiles files in, but maybe javac is invoked more than once? Or could it be down to the naming of the template file, or dumb luck...
Anyway, this is my experience - the student's .class file overwrites the support file's .class file. (I may have confused things by suggesting that .java files were being overwritten.) Maybe that's a less surprising thing than the student's answer isn't used and a file they can't see (the Support file) is used.
However, it would be good to confirm if the compiler is invoked twice and in the order above, or if something else could happen, because right now I'm suspecting it is just how it worked out on this occasion and in another example the support file could be compiled second.
And to be clear: they're not uploading files, they're pasting text into the answer box.
Thanks!