Computer Science 161

Laboratory Session # 4

Thursday, Nov. 13

Part I:  A laboratory exercise on main programs and a new way of submitting programs.

Begin by creating a new Java project (call it Hello) and a new class (Hello).  Do nothing to the class defined in the template (i.e., do not change anything in the class definition provided), but add to the end of the class definition (before the final '}') a public static void main(String[] args) as follows:

public static void main(String[] args)
{
    System.out.println("Hello, world!");
}

Run it to make sure that everything is working.

Now we need to set some Java preferences (it is possible that you may need to do this on every machine you use, but I'm not sure of that).

  1. Begin by going to Tools -> Preferences -> Extensions from the main Java window
  2. If your name does not turn up, enter it along with your email address.
  3. Add the server name:  smtp.ups.edu (note change:  not mail.ups.edu)
  4. I have added my username, but I am not certain that this is required.  It works if you enter your username in the 'Name:' box. 
  5. Leave everything else as is.  Click on OK

You should only need to do this once (but you may need to do this once for each machine you use).

  1. Go to the handouts folder for this class on Hedwig, and locate a file called submission.defs.  Copy this into the folder with the name of your project (you will need to do this for each project from now on).  You can also pick up a copy of this file by clicking this link and saving the file in your project directory  (I'll be doing this step in the lab as a demo Thursday if you have any problems with it).
  2. Now go to the Tools menu item in the Java window.  Make sure that Hello is still there.  Select the bottom-most option, Submit.  If you are running BlueJ on some system (like a Mac) other than Windows, you may need to close the BlueJ project and re-open it before doing this.
  3. A Submitter window should appear (notice how much these forms which appear have the appearance of the JOptionPane class we have been looking at).  Click on Browse.  A Select Submission Scheme should appear.
  4. Select the line (there should be only one) with CMPU 161a (MTThF at 11:00), and click OK
  5. The Select Submission Scheme window should disappear, bring back the Submitter dialog box.  Click Submit..
  6. You will be given the option of adding a message.  Do so if you want - it is not necessary.
  7. Clicking OK (as I have set things up), will bring up yet another dialog box asking for your password.  Enter your usual password and click OK
  8. The Submitter window should indicate that "All seems ok."
  9. This sends me a JAR (zip) file with all your files, and I should be able to run your program and view your source files from it. 

When you try this out (at least for the first time), I will send you a note saying that I have received your Hello file.

Try this out!  We will use this scheme from now on (after this Tuesday, anyway) for submitting programs.  Many thanks to Brad Richards for pointing out this neat scheme for submitting programs and clearing up points in it!

Exercise (to be due next Wednesday, November 19).  Using a copy of your latest inventory program, modify it as follows:

  1. Take out all of the JOptionPane stuff (make sure you are doing this in a copy of your latest inventory project - we will put the JOptionPane stuff back in (and more!) for the exercise following this.
  2. Add a main program (as in HashMapExample) to serve as a test driver.  The test driver should add 3 - 4 parts to the HashMap, list them out, delete one, and list out the resulting list.  Each test should be accompanied by a suitable message (use System.out.println for all printed messages).
  3. Convert the ArrayList to a HashMap.
  4. Modify the listing routine to use only the for loop discussed in class.
  5. The test driver should add 3 - 4 parts to the HashMap, list them out, delete one, and list out the resulting list.  Each test should be accompanied by a suitable message (use System.out.println for all printed messages).
  6. Following the steps above, submit your project using the Tools -> Submit option.  I will send you a reply acknowledging the receipt of your project. 

Please note:  Since I will be responsible for unpacking, printing files, and running your project it may take a few extra days to get your graded projects back to you.