Link to Codecrunch is here!
Creating a task for CodeCrunch involves the following steps:
You first need to decide on the statement of the problem.
This could be in the form of testing a particular concept taught in class,
or solving a full-fledged problem. You will also need to decide on how the program is to be tested,
either using jshell, by running the program via input/output, or both.
Let's use the following as the solution of a task. You may create as many class files as you like, but do note that if you wish to test program input/output via a main method, this method must reside in the Main class.
import java.util.Scanner;
class Main {
static String read() {
System.out.print("What's your name? ");
return new Scanner(System.in).next();
}
static String hello(String name) {
return "Hello " + name;
}
public static void main(String[] args) {
System.out.println(hello(read()));
}
}
After a successful compilation,
javac Main.java
think of what you want to set as tests. In the above, you can either
$ jshell Main.java
jshell> Main.hello("Mickey")
$.. ==> "Hello Mickey"
jshell> /exit
| Goodbye
$ java Main
What's your names? Mickey
Hello Mickey
Before proceeding, compile your solution, test and run your program to make sure that you have a working solution.
In order to make your program available for your peers to practise, you need to also provide input/output files. Let's use the same two test examples above.
The input file is simply the input that a human user will type during testing. For jshell testing, name your input file ending with a .jsh extension. On the other hand for input/output testing, name your input file ending with a .in extension.
Main.hello("Mickey")
/exit
Mickey
Using the input files, you can redirect the output of the test to the corresponding output file. These files should end with .out extension.
jshell -q Main.java < test1.jsh | dos2unix > test1.out
java Main < test2.in | dos2unix > test2.out
Mickey
Take note of the following:
You may also create as many tests as you like. To maintain some ordering to your tests, it is advisable to keep to the same naming convention, but add a running suffix, e.g. test1..., test2..., test3..., etc.
jshell -q Main.java < test1.jsh | dos2unix | sed s/^.*==\>/==\>/g > test1.out
You should now have the java source files, input and output files. You will need to create three directories:
The file directory structure will look something like this:
$ ls *
Main.class
input:
test1.jsh test2.in
output:
test1.out test2.out
solution:
Main.java
Now zip the three directories using your favourite zip utility. For example, using zip in unix/linux:
$ zip -r hello.zip input output solution
adding: input/ (stored 0%)
adding: input/test1.jsh (stored 0%)
adding: input/test2.in (stored 0%)
adding: output/ (stored 0%)
adding: output/test1.out (deflated 21%)
adding: output/test2.out (stored 0%)
adding: solution/ (stored 0%)
adding: solution/Main.java (deflated 45%)
$ ls *
hello.zip Main.class
input:
test1.jsh test2.in
output:
test1.out test2.out
solution:
Main.java
Now, log in to CodeCrunch. You have been given superuser access to the course CS2030P in order to create tasks.
Notice that your task is now listed in the task list under Manage Tasks
Before making the task available for your peers, you should test it at least once.
Now click on the Tasks tab again, and click View. Upload your solutions the usual way, and view you submission to see if everything works.
When you are ready to release your task in the course CS2030, edit your task again, and click the Categories tab. Select Peer Learning and click Link.
CodeCrunch has been set to periodically look for new tasks with the Peer Learning category and link them to the main CS2030 course. Once linked, you are still allowed to update your task, if deemed necessary.