CSE 373 -- Data Structures and Algorithms

Winter 2001

Department of Computer Science and Engineering, University of Washington

Steve Tanimoto (instructor)

Assignment 2

Version 1.01 (due date and other adjustments as of Jan. 22)

Applets that Process Text and Manipulate Structures 

Due date and time: Tuesday, January 22, 2001, at 6:00 PM (extended to permit adjustments to the input boxes (use TextArea, not TextField) and JDK version of the compiler (use 1.1 for final compilation, please).

Turn in this assignment by filling in the A2 online submission form.


 

Title: Applets that Process Text and Manipulate Structures.

Purposes: Practice and demonstrate your ability to create Java applets. Create a command parsing and interpretation tool that can be used in later assignments.

Instructions:  Do parts A, B, and C.
Part A.  Create a Java applet that contains a text area into which an online user can enter commands.  Your applet should parse and process the commands according to the version of Part A that you do.  To obtain your version, add up the digits of your student number to obtain a value we'll call Sum.  Then compute V = (Sum mod 3) + 1.  Then the value of V gives the version you're assigned.

  Version1. Your applet should maintain an integer variable "Cash-on-hand" and accept commands such as those below.  When first started, the value of this variable should be 0.  The applet should show the value of this variable on the screen whenever it is running.  There should also be a bar displayed whose length (or width, if you prefer) is proportional to the absolute value of Cash-on-hand, and whose color is Black if the value is positive, and red if the value is negative.
  "INCREMENT BY 5"
  "DECREMENT BY 17"
  "RESET"
If the user's input is not a valid command, then an error message should be displayed by drawing a string on the Applet panel area.

  Version 2. Your applet should maintain three integer variables, Red, Green, and Blue.  It should accept commands such as those below.  After each command, it should update the variables and update the color of a rectangle to show the current Red, Green and Blue values graphically.  The "Clear" command should set the color to Black.
  "SET RED 255"
  "SET GREEN 127"
  "SET BLUE 100"
  "CLEAR"
The values should be in the range 0 to 255 and if they are not, then you should issue an error message (painted on the Applet panel area somewhere).

  Version 3.  Your applet should keep track of the radius, center X position, and center Y position of a circle.  The initial radius should be 25 and the initial center position should be (0, 0), and this point should refer to the center of the applet's region on the screen.  The applet should accept commands such as the following ones and update the circle appropriately.  The circle should be displayed properly whenever the applet is running.
  "SET RADIUS TO 10"
  "SET CENTER TO (40, 30)"
  "RESET"
Handle any incorrectly formulated commands with an appropriate error message.

Part B:  Create a Java applet that accepts commands that manipulate the values of a set of words.  As in Part A, use a text area to allow the commands to be entered.  The applet should be able to parse and execute the commands.  The applet should devote most of the screen to the display of the set.  The elements of the set should be shown between curly brackets as in traditional set notation, e.g., { apple, banana, cantaloupe, date }.  Here are sample commands that should be handled:
  "ADD TO SET: apple"
  "ADD TO SET: plum"
  "REMOVE FROM SET: plum"
  "IS ELEMENT OF SET? plum"
  "REPORT CARDINALITY OF SET"
Note that if an element like apple is added and an attempt is made to add it again, the second attempt has no effect, since a set cannot have multiple occurrences of an element.  The set should be rendered on the Applet using Java's awt method g.drawString.

Part C:  Extend your Java applet of Part B by adding new kinds of commands that deal with particular types of data or that add general new operations.  Here are some suggestions:  (a) support keeping multiple sets, e.g., SET1, SET2, ..., SET5, and support defining one set as a union or intersection of two others; (b) support sets of integers rather than general words, and provide operations that remove odd elements, remove even elements, or that increment each element by a value given; (c) support sets of ordered pairs and operations to make a relation reflexive, symmetric, and/or transitive.  Provide on the web page some demonstrative examples of sequences of commands that your applet can handle.

Individual Work:  This assignment requires individual work.  Do NOT work in teams on this assignment..