CSC148HH lab -- week 2


This document contains the instructions for the week 2 CSC148H lab. To earn your lab mark, you must actively participate in the lab. For half marks, you must make a serious effort; for full marks, at least a couple of the programming steps must be completed successfully. We mark you in order to ensure a serious attempt at learning, not to make careful critical judgements on your work.

Here are the activities for this lab:

  1. Using the CDF computers.
  2. Setting up email forwarding.
  3. Using DrJava, playing with Stacks.
  4. Compiling and running programs from the keyboard.

Using the CDF computers

Sit down with your partner. The rest of these instructions call you two s1 and s2. Pick which one is which.

Repeat the following set of instructions twice, once for s1 and once for s2.

  1. Enter your user ID and password. Wait while the computer starts up.
  2. Start your browser, go to the CSC 148 web site, and select the "Labs" link. Find the Week 2 entries, and open the "Links" link, where you'll find the links referred to in this document, such as the email forwarding help mentioned in the next item. (There may be separate Links for each campus.)

  3. We will sometimes email information to everyone's CSC148 account. Unless this will be your primary email account, you must set up email forwarding. Do this now.

    Later, at home, check to see that you set up forwarding properly, by sending mail to yourself and seeing if it appears at the right destination account. Too often, we send messages such as assignment marks to students, only to find their addresses are wrong -- and we can't fix them. Please check your forwarding!

    Brief instructions, in case the web reference isn't enough: Create a file called ".forward" -- don't forget the period at the beginning of the name -- in your home directory, and put your forwarding address in the file. You can edit your .forward file in DrJava or Notepad. If you see someone having trouble, please help them. Some of the class are new to the CDF computers -- please make them feel welcome!

  4. Log out.

Using DrJava, playing with Stacks

In this lab, you'll be working in the pair programming model. Obviously, two programmers are involved, and we call these two people the driver and the navigator. Here are the definitions of the two roles:

And here is the most important rule for this lab:

Getting started with DrJava

Throughout the lab, you'll be switching back and forth between the driver and navigator roles. s1 will be the first driver, so s1 should now log in again.

  1. Save Stack.java, ArrayStack.java, and Driver.java to your hard drive. Make a new folder called "lab2", and put those files in it. You may need to right-click on the link to get a menu giving you the option of saving the file.
  2. Start DrJava by double-clicking its icon, and open all those files.
  3. Instead of the code shown in Driver's main, write code that:
    1. makes a new ArrayStack with a capacity of 10 elements that must all be Strings;
    2. puts the String "Hello" in the stack;
    3. removes the String from the stack and prints it.

Run your program. When you're done, show your TA.

Filling a Stack

Switch roles: now, s2 drives and s1 navigates.

Run your program. Do this in the Linux command line! When you're done, show your TA.

What kind of error do you expect will happen if you run your program with too much input to fit in the stack? Try it and see.

Emptying a Stack

Switch roles again: s1 drives and s2 navigates.

Run your program. When you're done, show your TA.

Using a different Stack implementation

Switch roles again: s2 drives and s1 navigates.

Run your program. When you're done, show your TA.

Arithmetic on a stack

You might not have time for this exercise; that would be OK. But if you do have time, try this:

Switch roles again: s1 drives and s2 navigates.

Sorry about that; we were probably having more fun than we should. Don't worry if you didn't finish the last part, but do think about it later. If you do finish, show your TA.