600.226: Data Structures

Spring Semester 2006: January 30, 2006 - May 5, 2006

Assignment 1: Warmup

Out on: February 2, 2006
Due by: February 8, 2006 by 5:59 pm for full credit (11:59 pm for 10% off, hard deadline)
Collaboration: None
Grading: Packaging 10%, Style 10%, Performance 10%, Design 20%, Functionality 50%

Overview

The first assignment for 600.226: Data Structures is mostly a warmup exercise. You will have to (re-)learn the Java language, including some of the more advanced features like interfaces. You will get acquainted with a number of Java tools such as javap and javadoc, as well as with a number of Unix tools such as tar and gzip. Convince us that you're in the right course!

Problem 1: Command Line Numbers

Your first task is to write a simple Java program Numbers that analyzes the command line it is given in a peculiar way. The program accepts any number of numbers, counts how often each number appears, and writes out a prose report about the statistics it collects this way. For example, the invocation

java Numbers 0 0 1 0 1 0 0 0 10 1

should generate the output

Among the ten numbers given
the number 0 occurs six times,
the number 1 occurs three times,
and
the number 10 occurs once.

Some of the rules for this are as follows: Always print the numbers given on the command line (0, 1, and 10 in this example) as numerals; print numbers you compute (1, 3, 6, and 10 in this example) as words if they fall into the range from 1 to 12 and as numerals otherwise; except for one or two occurances, then print "once" or "twice" as appropriate. Please take note of the way you are supposed to use punctuation marks! Your output should be as close as possible to the output given above.

Do not use anything aside from basic Java constructs, strings, and arrays to implement your program. Specifically, do not use any Java collection classes! You can of course use System.out in any way you see fit to produce your output. :-) If you feel like sorting something, think again! Maybe you don't have to "sort" anything to get this assignment done...

Problem 2: Counter Varieties

Your second task is to write a number of counters that can be used interchangably (at least as far as Java is concerned). You are given the following interface (put it into a file Counter.java):

/** The essence of any counter. */
public interface Counter
{
  /** Current value of this counter. */
  public int value();
  /** Increment this counter. */
  public void up();
  /** Decrement this counter. */
  public void down();
}

Develop the following:

All of your implementations should be resetable, and each counter implementation should contain a main method that tests whether the implementation works as expected. Finally, develop a seperate program PolyCount that shows how all your implementations can be used through a reference of type Counter only; the program should produce suitable output to illustrate the behavior of the various counters across the same sequence of operations; you can define an interesting sequence of operations yourself.

Hints

Deliverables

Please turn in a gzip compressed tarball of your assignment; the filename should be cs226-assign-1-login.tar.gz with login replaced by your Unix login name on ugradx.cs.jhu.edu (so I would use cs226-assign-1-phf.tar.gz). The tarball should contain no derived files whatsoever (i.e. no .class files, no .html files, etc.), but allow building all derived files. Include a README file that briefly explains what your programs do and contains any other notes you want us to check out before grading.

Grading

For reference, here is a short explanation of the grading criteria. Packaging refers to the proper organization of the stuff you hand in, following the guidelines for Deliverables above. Style refers to Java programming style, including things like consistent indentation, appropriate identifiers, useful comments, suitable javadoc documentation, etc. Simple, clean, readable code is what you should be aiming for. Performance refers to how fast your program can produce the required results compared to other submissions. Design refers to proper modularization and the proper choice of algorithms and data structures. Functionality refers to your programs being able to do what they should according to the specification given above; if the specification is ambiguous and you had to make a certain choice, defend that choice in your README file.

If your programs cannot be built you will get no points whatsoever. If your programs cannot be built without warnings using javac -Xlint we will take off 10% (except if you document a very good reason). If your programs fail miserably even once, i.e. terminate with an exception of any kind, we will take off 10%.

Bonus Problem

If you really want to impress us, try the following. Run javap -c BasicCounter and study the output produced for your void up() method. Document each instruction in this method as well as you can in your README file. To understand void up() it may or may not be helpful to look at int value() and void down() as well. Note that we won't give you extra points for this, but we'll give you extra kudos. :-)

Updated: $Id: assignment-1.html 308 2006-02-07 04:14:51Z phf $ Validate: XHTML CSS
Copyright © 2005-2006 Peter H. Fröhlich. All rights reserved.