Sometime during the year you’re probably going to assign your students a lab where they’ll write code in one class and have a separate runner class. Fortunately, that’s pretty easy to do in ClassCube.
For this example we’re going to create a simple output matching lab assignment with two files. One is a class called PrintSquare
where the student will implement a method to output a 5 by 5 grid of # symbols. The other is PrintSquareRunner
which is already implemented to call the printSquare
method inside the printSquare
class.
Here are the two files that we’re going to load into ClassCube.
Problem Settings
We’re going to create a new problem and set grading to output matching.
You can set timeout and visibility to whatever you choose.
Given Code
Since we’re going to be using multiple files, we’re going to go ahead and turn off the starter code. When you do this you’ll get a notice to be sure to include editable files in your problem. That’s okay. We’ll do that in a bit.
You can paste your runner code in here if you want. It does need to be a full class though. The reason we’re not is so that we can hide the runner if you don’t want your students to see it.
Expected Output
Next step is to add the expected output. For this one it’s going to be a 5 by 5 square of # symbols like this.
Of course, change this to whatever you’re looking for with your lab.
Adding Files
Now it’s time to add the files. Click on the Problem Files tab. You should see a screen that looks like this.
Click on the green Add File button and the screen should look like this.
Enter the full filename, including the extension, into the top field. The contents go in the large edit panel on the bottom.
If you’ve already created the file you can also drag and drop it onto the top section – the part with the filename field and toolbar buttons – and the filename and contents will fill in for you.
Do the same for the second file. If you’re using the same files as I am, it should look like this.
In this case I left the implementation of the printSquare
method up to the student, but went ahead and implemented the main
method in the PrintSquareRunner
class. If you’d rather leave the runner unimplemented, you can do that as well.
Saving and Testing
Switch back to the Settings tab and click on the Save button. That should take you to the problem edit page.
Notice that there’s a dropdown next to the Text button. This lists all files that are editable by the student. In this case it’s the PrintSquare.java
and PrintSquareRunner.java
files. They’re sorted alphabetically, so the PrintSquare.java
file comes first.
Running
Now, it’s like any other problem. Your students type in their code and press the Test button. Since this is an output matching question the expected output will be compared to the output from the submitted code. If there’s a match
And, it doesn’t matter which file they currently have selected. All the files will be sent to our servers to get compiled.
Hiding the Runner
If you’d rather not show the runner to your students, that’s easy to do.
Go back and edit the problem and click on the Problem Files tab. Next to the filename there’s a set of 3 buttons. One is an eyeball. Click that one and it should turn gray and switch to an eyeball with a slash through it like this.
Now when your students attempt this problem the runner will not be visible. But, it will still get sent with their code to our servers for compilation and running.
Be sure that if you hide the runner it is fully implemented since it won’t be editable.
Which file runs?
And before I go, just a little background on how output matching problems work.
When the files are submitted ClassCube looks for a main
method. All files are compiled, but the file with the main
is run. Specifically, the first file with a main
method is run. So you’ll want to make sure there’s not more than one main
.
Trying it out
If you don’t already have a ClassCube account and would like to see this in action this problem is available as a practice problem. The interface is slightly different on our public practice problems compare to inside of ClassCube, but the idea is the same.