For assignments in this class, you are allowed to discuss the problem, and your thoughts on the solution, with others. You are not allowed to exchange, in any way, code or anything that resembles code. If in doubt about whether a certain kind of interaction is allowed, ask me.
When sitting at one of the machines during lab time (or, for that matter, at any one of the public Windows systems maintained by the Computer Center), login will be a simple matter. The instructions presented in this section will work this week, but will be superceded by new instructions next week. Note that you need to use your College username and password (that is, the same one you use to retrieve your email.) Follow the steps below to login:
Once you've logged in, you can skip down to the section below entitled Your Assignment.
For this course, I will assume that you will use romulus.amherst.edu (a Linux server) to do your work. While you are welcome to do your work on another system (perhaps your own desktop/laptop machine), your code must compile, run, and be submitted on romulus.
You will be able to login and interact graphically with romulus from just about any machine with a high-speed connection. This section will desribe how to establish a VNC connection (which provides the graphical interaction) that is tunneled through an SSH connection (which provides encryption of your communication). The use of SSH is a good habit considering that the Amherst College network, as well as many other networks connected to the Internet, are open and rather insecure. If you are connecting from outside of the Amherst College network, you must use SSH tunneling to establish a VNC connection. I recommend that you use SSH tunneling under all circumstances.
The following steps will allow you to establish a VNC connection using SSH tunneling:
Connect to romulus using an SSH client configured to establish the tunnel: The choice of SSH client and the description of how to use it depends on the type of system that you are using. Below are instructions for Mac OS X, Linux/UNIX, and Windows systems. If you have another type of system (such as Mac OS 9), contact me and I will attempt to point you a web page or a person that can help you.
ssh -L 5900:romulus.amherst.edu:5900 username@romulus.amherst.edu
Of course, you would replace username with your username on romulus. Also note that if you are on the Amherst College network, you may not need to type the trailing .amherst.edu. Try it and see what happens.
You will be prompted for your password, so simply provide it. Assuming that your login proceeds normally, you will have established a tunnel for VNC conncetions (which use port 5900). Simply leave this login open so long as you are using VNC.
Windows: If you do not already have one, obtain an SSH client from The SSH home page. In their Downloads section, you may download the Windows Workstation client for free as a non-commercial user.
Once you have (installed and) started the SSH Client, select Edit -> Settings.... On the left side of the setting window, select Profile Settings -> Tunneling, and the right side of the window should provide you tunneling options. Click the Outgoing tab, and click the Add... button. Fill out the window that appears as follows:
Click OK on this window, and then click OK for the settings window. So that you don't have to do this again (assuming that this is your machine and not a public College machine), select File -> Save Settings.
Click the Quick Connect button on the main SSH window. Fill out the window as follows (nothing that the lower two values are most likely already correctly provided):
Click Connect, and shortly after, a window shoulda appear asking for your password to romulus. Enter it, and you should be logged into romulus and given a command prompt. At this point, you've established a tunnel for VNC and should leave yourself logged into romulus via SSH until done with your VNC connection.
Open a VNC connection: Again, the software used in system dependant, and I describe how to use software for each of the systems described above:
Mac OS X or Mac OS 8.1 (or later): Download a copy of VNCThing (you can also get it from the VNCThing homepage), which is a VNC client for this platform. (Note that this same VNC client is-or-soon-will-be available on the College's public Macs.) Start the application, and fill out the window that appears like so:
Click OK, and a new window should appear containing an entire graphical interface to romulus. Note that you can use Command-F to toggle between this format and a full screen mode.
Linux/UNIX: Again, recent distributions have a VNC client included. If yours does not, you can download the RealVNC client as a tarball, or for as an RPM package. You could also visit the RealVNC home page.
You must be logged into your machine and running an X-Windows server on your console. Open a shell, and give the following command:
vncviewer localhost
A new window should appear containing an entire graphical interface to romulus. To obtain full screen mode, trying pressing the F8 key, and a drop-down menu should appear with that option.
Windows: You can download a copy of RealVNC, or you can visit the RealVNC home page. This is the same VNC client used on the College's public Windows machines.
When you start your VNC viewer, fill out the window that appears like so:
(Note that this window may be different if you use another VNC client.) A new window should appear with an entire graphical interface to romulus. To obtain full screen mode, click on the upper-left corner of the window frame to get the window's drop down menu, and select the full screen option.
Login to romulus: Now that you are graphically connected, simply use the login window. A windowing environment will appear.
Now that you're graphically interacting with romulus, move on to the next section (Your Assignment).
Now that you are connected to romulus, you will obtain a Java file, make some changes to it, compile it, and run it. This exercise will introduce you to many of the tools you will use for this course. Follow these steps:
Open a shell: There should be, along the bottom of your screen, a set of icons. Among these should be an icon that looks like a computer screen with a little paw-print in the lower right corner. Click that, and you should get a new terminal window. Within that, a shell -- the command line program with which you will interact -- will start and you will be given a prompt.
Run a setup script: Just once, you need to run a script that will perform a bit of setup for your account. Enter the following command at the shell prompt:
source ~sfkaplan/public/cs12/setup
Make a new directory: Create a subdirectory within your home directory that will store the files that you use for this lab, like so:
mkdir lab-1
Change into the new directory: Change your current working directory to be the one that you just created, like this:
cd lab-1
Copy a Java code file: At the prompt, enter the following command copy a Java source code file from my directory into your own:
cp ~sfkaplan/public/cs12/PrintGrid.java .
Don't forget the trailing dot (.) -- It tells the shell that you want the file copied into the current directory.
Start XEmacs: We will use a powerful program known as XEmacs to edit Java source code. To start this program, simply type the following command at your shell prompt:
xemacs &
Note that for UNIX shells, placing an ampersand (&) at the end of a command causes that command to be executed in the background. That is, the shell won't wait for the program to finish before giving you a new prompt.
Open the file for editing: In your XEmacs window, select File -> Open..., and you will see, along the bottom of the window, a prompt that looks like this:
Find file: ~/lab-1/
XEmacs is asking you for a full pathname to the file that you want to open, and it's also filling in your current directory as the start to the pathname. In this case, you do want to open a file in your current directory, so just add to the line to make it read:
Find file: ~/lab-1/PrintGrid.java
Wrap lines and add color: XEmacs will open the file that you copied in its window. We want to make XEmacs automatically wrap around lines that are longer than 72 characters, and we want it to use color to highlight the code itself. In XEmacs, you can use the Alt key like a shift key; however, XEmacs refers to this key as the Meta key. Thus, if I indicate that you should enter M-x as part of a command, you should hold down the Alt key and press the X key. When you do so, on the bottom of its window, XEmacs will show you that you've begun a command with M-x -- many XEmacs commands begin this way.
The (not at all intuitive) command to get XEmacs to automatically wrap lines is:
M-x auto-fill
The (equally opaque) command for color-coding your text is:
M-x font-lock-mode
Edit the file: You will find, in the file, a comment that begins "YOUR TASK". It describes what you need to do to complete this small program -- specifically, implement a pair of nested loops to produce some output.
As you edit the program, notice some of the code that is already there. Note how input is performed, and how one method can call another. Also note that the code is well commented, consistently formatted, and uses a consistent and descriptive naming scheme for methods and variables. You should write your code in a similar fashion!
Compile the file: At your shell prompt, use the following command to compile your code:
javac PrintGrid.java
If there are errors in your code, the compiler will tell you where in the file that they were found. You must go back to your XEmacs window and try to correct the errors, and then compile again.
Run the program: To run what you've created, enter the following at the shell prompt:
java PrintGrid
The program may not execute correctly if there are errors in your code. If that is the case, you must edit the code to correct the errors, recompile the new code, and then run the program again. Be sure to remember to recompile after you edit the code.
As an aside, note that XEmacs is an exceedingly flexible and powerful program (although it does not have the most user-friendly interface). You would be well served to take the time to open an XEmacs window and select Help -> Tutorials -> English (or whatever language suits you best!). This will open a lengthy tutorial on XEmacs use that will show you a large number of capabilities that make XEmacs so well suited to editing programs and other text.
Copy the file ~sfkaplan/public/cs12/PascalsTriangle.java into your directory. Open the file, and you will find a method named makeTriangle() that has no body. You must fill in the body of this method.
Specifically, this method should create a two-dimensional array of integers that hold Pascal's Triangle. (It will be presented during the lab if you're not familiar with its structure.) A pointer to that array should be returned to the caller (the main() method) which will in turn call on printTriangle(), which is a method that is already written to emit the triangle.
Create a program with a class named Fib that calculates a given Fibonacci number, where the nth Fibonacci number is defined as:
Fib(n) = Fib(n-2) + Fib(n-1)
Your program should obtain n from the user using the User class at runtime, and must rely on a recursive method named calcFib to perform the calculation. The result should be emitted to the user, and the program should then terminate.
When you write this method, try mapping out how the activation stack would change over time as this doubly recursive method proceeded. It might, some day, resemble an exam question (hint hint).
When your work is complete, you will be able to use a special program to submit your work and to be sure that it was received. For this lab, you will submit your work with the following command at the shell prompt:
cs12-submit lab-1 PrintGrid.java PascalsTriangle.java Fib.java
The first argument to the cs12-submit program is the name of the assignment, which in this case is lab-1. The second and third arguments are the names of the files to submit, which here are PrintGrid.java, PascalsTriangle.java, and Fib.java.
Be sure to check the output of the cs12-submit program carefully to be sure that it did not indicate any errors. If you want to be doubly sure that your assignment was received, you can do the following:
(romulus)> cs12-check-submission lab-1
This program will indicate to you whether or not you have successfully submitted work for lab-1. Note that if you submit more than once, the most recent submission will clobber any previous submissions. Thus, if you want to correct something about your work, be sure to submit your entire set of files each time.