COMP 303 (Fall 2005) Assignment 1

Please submit an electronic version of your assignment (in PDF or HTML) using WebCT. The PDF format is preferred. If you choose HTML, please make sure that all the links are internal and work. Include your name and student ID. This assignment will be marked out of 20. It is your responsibility to hand this assignment in on time. Assignments not submitted on time will not be marked and will receive a grade of 0. By submitting your assignment you acknowledge your understanding of McGill University's academic integrity policy.

Required Problems

  1. Exercise 2.2 in the textbook.
  2. Write a series of use cases describing the behavior of a pop vending machine (e.g., the ones in the McConnell cafeteria). Make sure your use cases capture important variations (unavailable choice, coins unrecognized, etc.). Hints: a) See sections 2.6 and 2.12.1 in the textbook for examples. b) This should be short. If your find yourself going on for pages, something's wrong. c) Do not waste your time with fancy layouts, etc: your use cases should only include a title and a set of steps that describe the behavior of the machine as simply, clearly, and precisely as possible.
  3. Using Violet, draw a state diagram modeling your vending machine. Make sure to take into account all use cases.
  4. Name three classes you would use in implementing the controller for your vending machine. For each, briefly state why it would be a good idea to have this class (2-3 sentences each).
  5. Using Violet, draw a class diagram sketching the essential elements of your design (your three classes and their associations, and any important members).
  6. Briefly (2 paragraphs max) describe the knowledge of Eclipse you have acquired so far. Which non-obvious features do you find particularly useful? What do you find difficult to use or obscure?

Optional Problem

This part is purely optional. However, if you do it (successfully) you will get: 2 extra marks on this assignment (out of 20, to a maximum of 20), additional experience with Eclipse, basic knowledge of ECMAScript (Java Script), and a warm and fuzzy feeling of accomplishment.

Problem: Do exercise 2.4 in the textbook. Provide: the code you wrote to make Rhino work, the ECMA Scripts you tested, and describe two things you learned or observed.


The simplest way to use the code of Rhino is to link your project to the jar file containing the Rhino bytecode.

Assuming that you have created a new Java project and downloaded the zip archive containing Rhino: right-click on your project and select Import... | Archive file. Find the Rhino zip file and select it. In the content, find and select only the file js.jar. This will add it to your workspace.

Right-click on your project and select Properties | Libraries | Add JARs. Add js.jar to the list. This will add it to your classpath.

Look at the tutorial. You see that your code only needs to be only a few lines long.

To make your life real simple, you can write the ECMA script code in a separate file in your workspace, and load it with the following code:

BufferedReader lReader = null;
String lScript = "";
 lReader = new BufferedReader( new FileReader("script.txt"));
 String lLine = lReader.readLine();
 while( lLine != null )
  lScript += lLine + " ";
  lLine = lReader.readLine();
catch( IOException pException )

Experiment with various ECMA Scripts. Start with the code of page 41 in the book, then write a few statements of your own.