(back to the assignments page)
This laboratory is intended to get you started with the programs and systems we’ll be using and to give you an opportunity to complete your first substantial program for the class.
Even though most of you have used Eclipse before, please follow the introductory steps below carefully. Correcting configuration errors is not impossible, but it is time-consuming and distracting.
You should all have your accounts and passwords. Log into one of the computers in the lab. Among the icons in the dock at the bottom of the screen are a few that will be important for the class:
|
|
|
|
| Terminal | Eclipse | Safari |
You will use Terminal and Eclipse today. Safari is a web browser, through which you can read the course pages and documentation.
Open a terminal window and type the following commands. They will create a (private) folder for this class and a workspace within that folder.
cd ~/Documents
mkdir cs062
chmod 700 cs062
cd cs062
mkdir workspaceExplanation: The command mkdir makes a directory, and cd changes to that directory. The chmod command makes the directory private, so that others cannot see its contents. A few other commands for your information: ls lists the contents of the current directory, cd .. changes the directory to one directory higher up, rm removes a specified file and you can type man \<command> for any command and it will give you more information (man is short for “manual”).
Now start Eclipse. When it asks you for a workspace, select Browse and find the
~/Documents/cs062/workspace
folder you just created. Hit “Open” to select this folder. Then hit “Okay.” When you first open Eclipse, it may take you to a special “Welcome to Eclipse” screen. To close this, click on the “Workbench” icon in the upper-right corner.
From the bar at the top of the screen, select Eclipse then Preferences. Then in the Preferences window, expand Java and then Build Path, and then select Classpath Variables. Click on New and enter the name BAILEY and the path
/common/cs/cs062/lib/bailey.jar
These steps need to be done only once.
Eclipse works in units called “projects.” There will be one for each laboratory and each assignment in the class. To start a project, select File/New/Java Project. Give your project a name, like Lab1, but do not click Finish yet! Click Next, then Libraries, and then Add Variable. Add the variable BAILEY, and then click OK and Finish.
This step adds the bailey library (which we just setup) to our project so that our project knows that code is available. This allows us to use the import command in our code to bring outside resources (i.e. resources that are not included with java). For most of the labs, you will need to add the BAILEY variable to your project.
Your program for lab today is to write a text-based version of the Silver Dollar Game. See Section 3.10 of Java Structures for a description of the game. Make sure you understand how the game is played before coding it up! Think about the methods described there and choose an appropriate data structure to model the game. This is a time for discussion in the lab; do not hesitate to ask questions or share your thoughts.
The behavior, in the console, will look like this:
_o____oo_oo_ Next move? 6 4
_oo____o_oo_ Next move? 2 2
Illegal move!
_oo____o_oo_ Next move? 1 1
o_o____o_oo_ Next move?
...
ooooo_______ You win!!
The pairs of numbers after “Next move?” signify the location of a coin and the number of squares that the coin is to move to the left. Remember we’re computer scientists, which means we start counting at 0 not 1, so the leftmost square is location 0, not 1.
For this first exercise, we have given you a start on the code for the class TextCoinStrip. It can be found at /common/cs/cs062/labs/lab1/. To get it in to your directory (as well as the .json file you’ll need when submitting), copy the file TextCoinStrip.java into your src directory. To do this, go back to the Terminal and type:
cp -r /common/cs/cs062/labs/lab01/* ~/Documents/cs062/workspace/Lab1
Then, go in to Eclipse and “ctrl+click” on the project and select “Refresh”. You should now see the starting code.
Take some time to understand the code (you’ll be much better off spending 5-10 min. looking at the code before doing any coding yourself), then fill in the four missing methods.
toString which creates the string representation of the strip,isLegalMove which determines if a move is legal,makeMove which makes a (legal) move, andgameIsOver which determines if the game is completed.Before you leave the lab this afternoon, open up the Eclipse Submission Instructions.
For practice, follow these steps to submit your file TextCoinStrip.java. When you’re creating your folder to submit, you use the following format: Lab01_LastNameFirstName, e.g. Lab01_MawhorterPeter. You should submit this file as assignment lab01.
You are not being graded on what you submit today! The file need not be complete or error-free. We simply want to make sure that you can successfully submit files.
This is a suggestion for those who want to go beyond today’s exercise; it is not a course requirement. Let the computer assume the role of one player and experiment with strategies for the Silver Dollar Game. You may conduct your experiments in either the text-based or the graphical world. Here are some simple strategies: