Programming Assignment Checklist: Hamming Codes

Pair Programming

On this assignment, you are encouraged (but not required) to work with a partner, provided you practice pair programming. Pair programming is a practice in which two programmers work side-by-side at one computer, continuously collaborating on the same design, algorithm, code, or test. One partner is driving (designing and typing the code) while the other is navigating (reviewing the work, identifying bugs, and asking questions). The two partners switch roles every 30-40 minutes, and on demand, brainstorm. Before pair programming, you must read the article All I really need to know about pair programming I learned in kindergarten; you might also find these videos helpful.

If you pair program, you must choose a partner (of similar ability) from the same precept. Only one of you (you or your partner) should turn in the assignment code and the readme.txt file. Any late penalties will be assessed against both partners. Writing code with a partner without following the pair programming instructions listed above is a serious violation of the course collaboration policy, e.g., if one partner writes encode.toy on his own and the other partner writes decode.toy on her own.

Frequently Asked Questions

What are the goals of this assignment? To Learn about error-correcting codes; to learn to program in a machine language; and to appreciate the programming and debugging advantages of a structured programming language like Java over machine language!

I can't launch the Java Web Start version of the Visual X-TOY simulator. Any ideas? The program requires something called Web Start. When you installed Java initially, this was included. However, the last Windows security patch I applied broke this. If this happens to you, go to java.com and click the Get It Now button.

How do I format the TOY output? You can't. Just print one integer per line (0000 or 0001).

My program prints out the right answer, but then I get java.lang.NumberFormatException: null. What could be wrong? You are probably trying to read from standard input, even though it is empty. Be sure that your TOY program terminates when it encounters FFFF.

How do I write/comment a .toy file? To initialize a location in memory to have a value, write (on its own line) the index of the memory location (two hex digits), followed by a colon, followed by a space, followed by the value (four hex digits). Anything else on the line is ignored by the TOY simulator and treated as a comment.

TOY.java doesn't read in some of my instructions. Any ideas? Be sure that you follow the required format XX: XXXX. Check for duplicated line numbers and using the letter O instead of the number 0.

How much do I need to comment my TOY code? At a minimum, you should:

Developing a TOY Program

To simulate the execution of your program on a TOY machine, use either the bare-bones TOY.java or the full-blown Visual X-TOY simulator. To get started, download the sample TOY program multiply.toy.

Command-line TOY simulator. The command-line TOY simulator is available in the ftp directory hamming. You need the three files TOY.java, StdIn.java, and In.java. To use the simulator, do the following:

Visual X-TOY simulator. The Visual X-TOY simulator from lecture provides lots of useful development features. There are three modes (edit, debug, and machine).

Input, Output, and Testing

Input. Copy the hamming directory from the COS 126 ftp site to your computer.

Execution.  To redirect standard input from a file, execute your programs with:

% more encode1.txt 
Terminal
---------------------------------------
0001 0001 0000 0001 
FFFF

% java TOY encode.toy < encode1.txt
...
Terminal
---------------------------------------
0001
0001
0000
0001
0001
0000
0000
...

% more decode1.toy
0001 0000 0000 0001 0001 0000 0000
FFFF

% java TOY decode.toy < decode1.txt
...
0001
0001
0000
0001
...

Testing.  The most complete way to test your TOY programs is to encode and decode all possible inputs.

Reference solutions.   As a special bonus, we provide Java source code HammingEncoder.java and HammingDecoder.java for the two programs. You are welcome to examine this code and use it to develop your TOY programs.

Debugging Tips

Here are some debugging hints that may help you out.

Enrichment