For each assignment, you are required to post your complete (or nearly completed, not partially completed) code to your web page. If you do not have a web page, you can either create one on your netfiles account, dcshome account or ews account. You should include all the relevant source code (if you are using an IDE, do not include workspace files) as a zip file. Then post the URL to your zip file on the newsgroup. The TAs and other students must be able to access your file by Friday 12 a.m. (the day the assignment is due).

Post questions, concerns and comments to the class newsgroup at class.cs242


Animal Quiz

Assignment 10 - April 1, 2006 (This is not an April Fool's joke!)
Due: Friday, April 7, 2006
Language: Java 1.5

Objectives:

Code Complete, Chapter 22 - Developer Testing

Programs do not acquire bugs as people acquire germs, by hanging around other buggy programs. Programmers must insert them.
-- Harlan Mill

For this assignment, you would need the Eclipse IDE. You should get the latest version (currently 3.2M5a) since it has a lot of improvements that make it faster. The first impression some of you might have is that Eclipse is slow and bloated. I completely agree. However, Eclipse is one of the best development environment for Java and it would be to your advantage to learn about it. You might also need the Java 1.5 SDK from here.

You also need the starter file from here. It contains some advice on doing unit testing on your files. Unzip this file somewhere since you will need it in the next section.

  1. Start Eclipse.
  2. It will ask you to create a new workspace. Using the suggested path is fine. If you want to move the workspace somewhere else, that is fine too.
  3. Once Eclipse starts, you will be presented with a welcome screen. You can explore the different features of Eclipse by clicking on the images in the center of the screen.
  4. Select File > New > Project.
  5. In the New Project dialog, select Java Project and click next.
  6. For the "Project name" field, enter "AnimalQuiz".
  7. For contents, select the "create project from existing source" and select the AnimalQuiz folder from the file that you unzipped. Also, make sure that JRE says jre1.5.0_xx.
  8. Click finish. Everything should load fine and you will have a project called AnimalQuiz and three packages: com.cs242.animal, com.cs242.animalTest and com.cs242.testExamples. It should also have the JRE System Library and junit.jar files. Verify that this is indeed so before continuing.
  9. Now select the ExampleTests.java file inside the com.cs242.testExamples package. Right-click and select Run as > Unit Test. Make sure that there is a green bar.

At this stage, you should proceed to read Chapter 22 of Code Complete 2. There are some guidelines on how you can test your program. For this assignment, we will focus on unit testing using the white-box approach (pp 499, 500). If this is the first time you are doing unit testing, most of the material might not make sense to you. So, my suggestion is to read Section 22.3 thoroughly and skim the rest. Do the exercise below and compare the tests that you wrote to the guidelines listed in Section 22.3. Finally, once you are done with the coding, read through the rest of Chapter 22. You should have a better feel for it by then. Also, reading the chapter will help you explain why you think the testes you wrote are good tests.

This is how you should proceed with this assignment. Open the com.cs242.testExamples package. There are 5 files here. Read through them in this order, paying special attention to the comments. There are some exercises in those files that you should complete.

  1. Money.java, MoneyBag.java
  2. MoneyTest.java
  3. MoneyBagTest.java
  4. ExampleTest.java
While completing the exercises, you will need to make changes to both Money.java and MoneyBag.java.

Now, here is this week's assignment. You will be implementing a simple console animal quiz that will try to guess an animal that you are thinking of. You can find an online implementation here. Here is an example run of the program. Text in bold is user response.

Think of an animal...
Is it a whale? (y or n)
n
You win. Help me learn from my mistake.
What animal were you thinking of?
a rabbit
Give me a question to distinguish a rabbit from a whale.
Is it a small animal?
For a rabbit, what is the answer to your question? (y or n)
y
Thanks.
Play again? (y or n)
y
Think of an animal...
Is it a small animal? (y or n)
y
Is it a rabbit? (y or n)
n
You win. Help me learn from my mistake.
What animal were you thinking of?
a capybara
Give me a question to distinguish a capybara from a rabbit.
Is it a kind of rodent?
For a capybara, what is the answer to your question? (y or n)
y
Thanks.
Play again? (y or n)
y
Think of an animal...
Is it a small animal? (y or n)
y
Is it a kind of rodent? (y or n)
y
Is it a capybara? (y or n)
y
I win.
Play again? (y or n)
n

In summary, the program asks the user to think of an animal and then asks a series of questions to narrow the possibilities. When the program guesses wrongly, it asks the user to supply a question that can help it determine that animal in the next run. The series of questions will be stored to disk so that the next time you run the program, it will remember the questions and the answers.

Do not worry about the 'a' and 'an' particle for the animal. Just treat everything as being addressable by 'a'.

Put all your code in the com.cs242.animal package. And for this assignment you should write tests for each class. Each test should exercise some of the methods in each class. You should be able to give reasons why the tests you wrote are good tests. Put those test into the com.cs242.animeTests package.

Grading:


Image Editor - Compression

Assignment 9 - March 23, 2006
Due: Friday, March 31, 2006
Language: Any programming language of your choice

Objective:

You will implement a compression algorithm and integrate it with your Image Editor so you can:

You are free to use any compression algorithm you devise or read about, but you are not allowed to use a prebuilt library. As a recommendation for simplicity, run length encoding will probably be the most straightforward compression, but the benefits aren't very impressive unless there are large patches of solid color. A much more enjoyable algorithm is Huffman Coding, which is not that much more dificult as far as implementation goes, but can achieve much better results.

You may want to think about making your compression format general, so you could use it in other applications as a library you plug in. In this case, it should clearly be a lossless compression scheme. You could also make the scheme specific to images, so you get better compression for those kinds of files. If you are only compressing images, you may want to consider lossy compression. Either way, the compression code you write should not be tightly coupled with the Image Editor code itself. It should be something like one call to compress and one to decompress.

You are encouraged to use the newsgroup to ask the TAs and your classmates questions, but to get you started, here are some links:

Your implementation should not be trivial (compressing everything to a single pixel, for example), but we encourage you to play with different kinds of compression.

Grading:


Image Editor

Assignment 8 - March 11, 2006
Due: Friday, March 17, 2006
Language: Any programming language of your choice

Objective:

You will implement a picture editor that is capable, but not limited, to the following features:

While you are free to use any language or framework that you choose, we suggest taking a look at Java and the facilities that it provides. Here are some links:


Students in the past have also had success with using ImageMagick to perform image manipulation. There are bindings for interfacing ImageMagick with most programming language. ImageMagick lets your perform the image manipulations but you still need a toolkit for the GUI.

If you have any questions about Java Swing, Eclipse or Java 2D, post your questions on the newsgroup. For those students who have been sticking with one programming language so far, I suggest trying to this assignment with a different language. Also, if anything is ambiguous, ask questions early!

Grading:


Allowing Comments on Your Portfolio

Assignment 6 and 7 - Saturday, February 25. 2006
Due: Friday, March 10, 2006 (EXTENDED!)
Language: Any programming language of your choice

Objectives:

Since this might be the first time some of you are doing web programming, do not hesitate to ask if you have any questions. If you find that you need more time, just let us know. But let us know EARLY, preferably by Wednesday.

Everyone has done a fantastic job on their portfolio so far. Right now, you can change the look of your portfolio and quickly add your latest projects to it. Also, you can place it on the Internet and let everyone else see what you have done. One more thing that would be nice to have is the ability for visitors to comment on your projects.

Instead of the boring type of comments that you can find on web blogs, you will be implementing threaded comments. For examples of threaded comments, please visit slashdot.org. All that we require is that we can reply to comments. That means there is some hierarchy to the comments. If you want, you can also implement sorting by date, comment score, etc.

While having comments are nice, sometimes some random stranger might leave profane terms in the comments. Also, some people might also flood your comments by leaving link to other sites. You will think of ways to avoid both of these problems. There are various different ways to do this and it will be interesting to see what everyone comes up with. For instance, some sites make you actually type in the word displayed on an image before allowing you to post a comment. Another way would be to just allow all comments but you, as the web author, have to release each comment before they are displayed.

Another solution suggested by a previous student who took the class, is implementing a simple word based filter. So for certain words in your dictionary, you would replace them with some kind of euphemism. Use your own imagination to see what words and their euphemisms you can come up with. ; )

While allowing comments is nice, it also brings up some potential security issues. The user can embed Javascript/HTML that can break the layout of your page. Also, if you are not careful, the user can enter a SQL query as a comment and delete all the tables in your database. We will not be focusing on those issues for this assignment (yet!) but go ahead and take preventive measures if you know how to.

This project will require using a database and some web scripting language. If you already have a web server set up, you can go ahead and use it. Nonetheless, we will be providing everyone with PHP and MySQL access on the CSIL machines. Details on how to access them will be sent to your e-mails.

While the description of the project is simple enough, your main hassle would be dealing with PHP and MySQL (or whatever language or database of your choice). Why? Here are a list of things that you need to keep in mind as you approach this:

As you can see, you need to make some design decisions. Deleting comments would be the thing you should worry most since it can lead to missing dependency issues. And do not say that you would not delete comments. There will be some that you want to delete.

Some technologies that you might be interested in trying out:

If you have any other suggestions, please post them to the newsgroup.

Nicholas: I have books for Ruby on Rails and AJAX. You may loan them from me.

Grading for March 3:

Grading for March 10:


Parsing Your Own Metadata for a "Programming Portfolio"

Assignment 5 - February 17, 2006
Due: Friday, February 24, 2006
Language: Any programming language of your choice.

Main objective:

Sub-objectives:

Pair Programming

TWO programmers working side-by-side, collaborating on the same design, algorithm, code or test. One programmer, the driver, has control of the keyboard/mouse and actively implements the program. The other programmer, the observer, continuously observes the work of the driver to identify tactical (syntactic, spelling, etc.) defects and also thinks strategically about the direction of the work. On demand, the two programmers can brainstorm any challenging problem. Because the two programmers periodically switch roles, they work together as equals to develop software.
-- Laurie Williams
North Carolina State University Computer Science

Basically that is all pair programming is. Pair programming is usually emphasized as one of the best practices for eXtreme Programming (XP). The good news is that you can pair program without following all the pillars of XP.

For this assignment, we have already determined the pairs that will be working together. Please refer to the list on the newsgroup.

Here are some tips to make pair programming successful:

The instructions that follow might be a little confusing, so please read them carefully and ask questions when in doubt.

Your portfolio generator currently generates XHTML that is hard coded for a specific set of known tags with known relations. This makes your code rigid and hard to change. Imagine if you needed to include more information in your generated portfolio. How many places would you need to change in your code? 2? 3? If it is more than one, then you are violating the DRY (Don't Repeat Yourself) principle. This time, you are going to extend the functionality of this application by moving much of the data and the definition of the finite state machine to be outside of your source code.

You will do this by:

  1. Read a file of your own design (the format file) that represents the relationship between legal tags. The format of this file is determined by you.
    • Example of the format that describes the metadata that we gave last week:
      portfolio: project
      project: title, date, author, summary, files, versionhistory
      date: day, month, year
      files: doc, code
      doc: f
      code: f
      versionhistory: version
      version: number, info

      How to interpret this data. This means that portfolio can only contain the project tag as a direct child. The project tag can contain title, date, author, summary, files and versionhistory tags. So this example of a format file tells us the tags that we can expect.
    If you know what a DTD for an XML file is, this is exactly the concept that we want to except that you do not need to use a DTD file. Creating an format file that specifies the list of tags and their hierarchy allows for new tags to be created and will allow that little code needs to be changed to handle those new tags.
  2. Come up with a way to generate your metadata file automatically or at least make it less cumbersome to write. For instance, last week, you wrote your metadata file by hand. I doubt that it was a fun activity. What we want you and your partner to do is come up with some way to do this automatically or make it less error prone. A good thing to do is to generate this metadata file automatically based on your project directory structure. Of course, you might need more information than this, so maybe you can include a README file in the project root directory that tells you the author, a description of the project, and some other details. Additionally, you could grab the version history information from your source code repository.
  3. Parse your metadata file. You do not need to use XML if you don't like it. For instance, you might want to use YAML since it is simpler and probably easier to read than XML. Or if you elect to use XML, you are free to use any XML library.
  4. Generate the XHTML. Do not skim on the eye-candy but do not go overboard as well. Last week most of you already made use of CSS to simplify the layout. This week, make the layout even more presentable. If you cannot come up with your own design, borrow one from here and remember to credit them.

We are not making any limitation on the programming language or the technologies that you can use. Use whatever you need to make this an application that you will use. Add all the bells and whistles that you want. We want to see you use this application not only for this class but for you future classes as well. This is the main purpose of this assignment.

Grading:


Parsing Metadata for a "Programming Portfolio" with a Finite State Machine

Assignment 4 - Feburary 12, 2006
Due: Friday, February 17, 2006
Language: Any programming language of your choice.

Objectives:

NOTE: Some of you will already be asking: Why shouldn't I just use an XML library to parse the metadata? Short answer: Just don't do it. Longer answer: Yeah, we all know that we should use an XML parser. However, the purpose of this assignment is to get you to write a finite state machine. And parsing the metadata makes for a good opportunity to use one. So just do the assignment with a finite state machine.

We mentioned that we will be asking you to produce a program portfolio, where prospective employers can get an overview all of your projects. This is the first of several assignments in which you will write a program that produces that portfolio. The input to this program will be a file containing information about your projects (a "metadata" file). The output will be one or more XHTML files that, together with the files named in the metadata file, will be the portfolio.

This metadata file includes information about each of your projects. The format of this file is specified in an attached file. Please right-click and choose Save As.. since viewing the .txt file in your browser will hide all the metadata tags. While you may add enhancements to the format, make sure that your program is still able to read in a metadata file specified in the original format.

You need to do the following:

  1. Read in a metadata file as input.
  2. Parse this file; the format is specifically designed to allow the use of a Finite State Machine for parsing and you should use one. Create an internal representation of the metadata.
  3. Generate XHTML files that present the information in the metadata file. There may be more than one XHTML file. The entry point for navigation through the portfolio should be named index.html. Note that the metadata includes the names of other files, such as source code files. These files should be linked from your portfolio page. Obviously, for the portfolio to be viewed, these files must also be in the directory containing the generated XHTML.

XHTML is just stricter HTML.

These XHTML files should offer a nice interface for browsing your projects. That is, you should be able to open the index.html file and browse to a page for any one of your projects, where you can see more detailed information and access the source code. The format and presentation of these files are up to you. You may make use of CSS or Javascript. For example, you could transform your metadata into the S5 format to convert them into a slide show.

Grading:

Note:


Reading Mike's "run-once" recovery program

Assignment 3 - February 6, 2006
Due: Friday, February 10, 2006

Objective:

For this assignment only, you do not need to turn in your code by Thursday night since everyone essentially has a copy of the original code. We are interested in your in-class presentation of what the program does and what you could do to make it more readable.

For this assignment, you would need the recover.c file from here. As the title suggests, this program was written to "run-once" and it was for a very specific version of OS and hardware. In fact, you probably might not even be able to compile it since it uses an antiquated compiler.

The assignment is to try to understand how the recovery program works and comment on style, comments, etc. Take a portion - say one function and re-write it in a way that is more clear. This may only be formatting the text so that it's more readable and adding comments. No one will be judged on syntax AT ALL. No one will be judged on the "correctness" of their comments or efforts to improve readability. If you see something that isn't clear, make a comment to that affect. If you THINK a line of code means something but you're not sure, make a comment and write a line that you think would be more clear to replace it.

What this program actually does: This program recovers the entire contents of a disk drive in FAT16 (a specific disk format that was once used by DOS and Windows) by making a BIOS call that gets each sector of the file and writing it to a new disk. It does this recursively, tracing through all directories and subdirectories.

Each entry in the directory tells whether an entry is a file or a directory and the location of the first sector of the file. There is a table entry (File allocation table or FAT) for each sector that tells where the next sector of the current file is. So if the first sector of the current file is 100, I could look in entry 100 and find the sector number of the next sector of the current file. I can repeat this until the next sector indicates that I should stop.

Some resources previous students found useful for this assignment:

Grading:


Raster Analyzer - Optimized!

Assignment 2 - January 30, 2006
Due: Friday, February 3, 2006
Language: Use the same one you did Assignment 1 in.

Objectives:
Modify the Raster Analyzer program from last week.
Optimize it using the methods described in class.

Read in the provided binary file. The header provides the number of rows and columns as 16-bit integers. Here is the description for the file header:

offset type description
0 16-bit int header length
2 16-bit int rows
4 16-bit int columns
6 16-bit int longitude of lower left corner
8 16-bit int latitude of lower left corner
File header description

A sample file is available here. This file is in little-endian binary format. So you would have to use an machine that has a x86 processor to read it for instance.

Keep a copy of your code from last week. You will need it so that you can compare the results of the profiling. We will be using gprof to compare the time spent in each function. For a quick start on how to use gprof look at this site. The current version of Mac OS X has some issues with gprof so you should use Saturn or Shark instead. Both applications are available as part of the CHUD tools. Instructions on how to use these applications are found in their Help menu. We will not be using any advanced features; instead we would just like a simple way to be able to compare the time taken to run both versions of your program.

Based on our observations from last week's discussion section:

Grading:


Raster Analyzer

Assignment 1 – Jan 23, 2005
Due: Friday, Jan 27, 2005
Language: Write this in C or C++.

Objectives:
Write a program to read in data points into a grid. The data points should be bytes (characters).
Refresh your memory on file I/O and pointer manipulation in C/CC.

Generate a 1-byte code for each element in the grid that indicates whether each of the 8 neighbors of any given element in the grid is equal to the current element. Your output will be a grid of values that has the same dimension as the original grid. Save the output to a file.

Create your own input data. Expect an example input file in binary form for the next version of this assignment.

Here’s an example simple input data file. You don’t have to use this method but it suggests a way if you can’t think of your own. The first line is the dimensions. Data follows.

6 26
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxy
yzabcdefghijklmnopqrstuvwx
xyzabcdefghijklmnopqrstuvw
yzabcdefghijklmnopqrstuvwx
zabcdefghijklmnopqrstuvwxy

Do not assume that all characters are printable. In other words, values in your output grid may be anything from 0-255. For convenience during development you may use data of your own construction as input. A simple way to create this data is by using printable values.

An example of encoding the values for the byte codes is: Use the highest bit in the byte code for the element above and to the left (northwest) of the current. Use the next lower bit to indicate the neighbor immediately to the right (east) of the last and proceed through the neighbors in a clockwise fashion.

Along the edges of your grid you will have no neighbors. Assume that the empty neighbor elements are NOT equal to the current element.

Bring your code to discussion sections on Friday. Location to be determined. Each student must present code to your classmates. If you have a laptop, bring it to use for your demo. If not, put code where you can get to it (e.g. netfiles, ews, csil). Sometimes we will actually make changes and try them out in class.

First: show code that works even if it isn’t complete.
Second: show code that you’re working on.

We will give you comments on your code and presentation so that you know what to expect for subsequent weeks.