COS 226 Programming Assignment Checklist: Randomized Queues and Dequeues

Frequently Asked Questions

What's a checklist? The assignment checklists are meant to supplement the assignment, and clear up any confusing points. They will also provide brief hints on getting started. They also include links to sample data files, reference solutions, and readme template files. Be sure to read the checklist before each assignment.

Is there anything else I should do before getting started? Please read the Assignments Page, including the collaboration policy, lateness policy, and submission system instructions if you have not done so already. The programming assignments will require a good deal of time. The final source code may not be that long, but creating and debugging the code is a serious time commitment. It would be a mistake to wait until after Tuesday precept to start your assignments. You may be able to ask more meaningful questions in precept if you already have worked on the program enough to know what the real difficult issues are.

The whiteboard submission system describes my file as a C++ program instead of a Java program. Am I doing anything wrong? Unlikely. We use the Unix command file -b Point.java to determine the file type, and it often confuses the two.

How should I generate a pseudo-random integer between 0 and n-1? You may use the following function for this assignment.

public static int random(int n) {
    return (int) (Math.random() * n);
}

What should my program do if remove is called when the queue is empty? You should throw a RuntimeException with an underflow error message. See Stack.java for an example.

Can you give me some examples of Watson-Crick palindromes? Yes: "AAAACGTTTT, "ATATATAT", and "". No: "AAAA", "AAAAGTTTT", "ATAATA", "ZZZZ" and "AaTT".

What is meant by uniformly at random? If there are N elements in the queue, then you should choose each one with probability 1/N (up to the randomness of random()), independent of past decisions.

What's the wrapper type for char? Character.

Can I make up my own names for the names of the classes and methods? No.

How serious are you about declaring only one variable in each client? Not entirely. You may declare O(1) extra variables provided it makes your program easier to read.

How should I format my code? Here are some that your grader will appreciate.

For reference, here are Sun's Code Conventions for Java.

How much do I need to comment my code? At a minimum, each file should contain your name, precept, login, date, a description of the program, and how to execute it. Also, include a comment for each variable, for each method, and for each well-defined chunk of code. Use some discretion here - for example, do not comment a loop index variable i. Generally, comments should describe what or why you are doing something, rather than how.

The compiler says that my program uses unchecked or unsafe operations and to recompile with -Xlint:unchecked for details. Usually this means you did a potentially unsafe cast. When implementing a stack with an array, this is unavoidable since Java does not allow arrays of generic types.

Testing and Submitting

Submission.   After you have submitted all of the required files (Deque.java, RandomizedQueue, Subset.java, Palindrome.java, and readme.txt) the "Run Script" button on the submission system will appaer. Be sure to hit the button and check that you submitted the right files and they compile cleanly.

Readme.   Use the following readme file template and answer all questions.

Possible Progress Steps

These are purely suggestions for how you might make progress. You do not have to follow these steps.

  1. Installing a Java programming environment. Follow the instructions from the Hello World assignment from COS 126 to install Java 1.5 on your system. If you have a previous version of Java, we recommend uninstalling it before upgrading. To develop your programs, you may also wish to download JEdit (a basic programming text editor). If you use an IDE (integrated development environment), be sure that it supports command line parameters, reading from standard input, and redirecting standard input and output.

  2. Getting started. Download the directory queues to your system. It contains the file StdIn.java that you will need to read in input characters from standard input. It is a revised version of the one we used in COS 126. If you skipped COS 126, see Section 2.4 for examples on using StdIn.

  3. Stacks and queues. Review the code we used in lecture for generic stacks and queues. See Section 2.6 of the booksite.


wayne@cs.princeton.edu
Last modified: September 27, 2005