Computer Science 136 |
Lab 1: Java, Unix, and the Silver Dollar Game
Due: Monday, September 19, 2005 at 9:00 AM
You should come to lab with a proposed design for your Coinstrip class that you will write for the "Lab Program" section of this assignment. These designs may be handwritten or typed. They will be checked at the start of lab and will constitute a small part of the grade for this week's lab.
Getting Started
During lab today, you will learn how to use the Java environment from the Unix command line on the CSLab Mac systems and get some practice writing Java code.
source /Network/Servers/cortland.cs.williams.edu/Volumes/Courses/cs136/bin/136in the command window each time you log in. Rather than type this command every time, you can make it happen automatically by adding it to the file .local_bashrc in your home directory.
ls cd cp mv rm mkdir pwd man chmod cat more grep head tail ln find rmdir wc diff tar
Identify the function of and experiment with these Emacs Commands:
C-x C-s C-x C-c C-x C-f C-x C-w C-g C-a C-e
C-d C-_ C-v M-v C-s C-r M-%
Learn these commands - you will use them often. Hints can be found in the Unix and Emacs web pages on the course website.
Make a subdirectory lab1 in this new directory for files related to this lab.
Warm-up Exercises
public class Example {
protected int num;
public Example(int initial) {
num = initial;
}
public int getNum() {
num = num + 1;
return num;
}
public static void main(String args[]) {
Example first = new Example(10);
Example second = new Example(20);
System.out.println(first.getNum());
System.out.println(second.getNum());
}
}
What would be printed if we changed the declaration of num to be
protected static int num;instead? What does this tell you about static instance variables? Explain briefly, writing your answer in a file lab1.txt.
Lab Program
This week, we will write the Silver Dollar Game at the end of Chapter 3. You should come to lab with a written design of the program.
For your design, you should first decide on an internal representation of the coin strip. Make sure your representation supports all of the operations necessary, i.e., testing for a legal move, printing the board, testing for a win, moving pieces easily, etc. You should think about alternative designs and be able to justify your decisions. You may read ahead a little to Vectors if you like, but the lab can be implemented with arrays.
Once you have decided on a representation, write down the set of operations supported by your data structure. In other words, what are the public methods of CoinStrip, and what do they do?
The document you bring to lab should include both a description of the representation and the operations on it. This initial design will constitute a fraction of your grade on the lab assignment.
Write your program in a file named CoinStrip.java. When you have finished the program, turn in CoinStrip.java using the turnin utility-- type turnin -c 136 CoinStrip.java.
Finally, answer the thought questions at the end of the lab. Put your answers in the file lab1.txt and submit that file as well.
As in all labs, you will be graded on design, documentation, style, and correctness. Be sure to document your program with appropriate comments (use Javadoc!), including a general description at the top of the file, a description of each method with pre- and post-conditions where appropriate. Also use comments and descriptive variable names to clarify sections of the code which may not be clear to someone trying to understand it.