CSE 373 -- Data Structures and Algorithms

Winter 2002

Department of Computer Science and Engineering, University of Washington

Steve Tanimoto (instructor)

Assignment 2

Version 1.01

Applets that Process Text and Manipulate Structures 

Due date and time: Monday, January 28 at 11:00 AM (changed from Friday, January 25, 2002, at 5:00 PM)

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. Gain experience working with a partner on a programming project.

Instructions:  Do parts A and B.
Part I.  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 numbers to obtain a value we'll call Sum.  Then compute V = Sum mod 3.  Then the value of V gives the version you're assigned.

  Version 0. Your applet should maintain an array of strings.  It should handle the following operators:
  CLEAR  -- should remove all elements from the array.  The initial state should be clear by default, too.
  INSERT-AT position, string -- should insert the string at the given position, shifting successive elements down by one.
  DELETE-AT position -- should remove the string at the given position, shifting successive elements back up by one.
  LIST-ELEMENTS -- should print out all the elements of the array, in order, separated by the semicolon and a space, i.e., "; ".

  Example
  INSERT-AT 0, Abe Adams
  INSERT-AT 0, Aaron Zucker
  INSERT-AT 2, Zoe Jana Quigley
  LIST-ELEMENTS
    Aaron Zucker; Abe Adams; Zoe Jana Quigley
  DELETE-AT 0
  LIST-ELEMENTS
    Abe Adams; Zoe Jana Quigley
  CLEAR
  LIST-ELEMENTS

  DELETE-AT 0
    error -- no element at position 0.

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 1. Your applet should implement the BRIDGE ADT given on our January 14 activity sheet.

  Version 2.  Your applet should implement a STACK ADT with strings for the elements, and with the operations CLEAR, PUSH, POP, TOP, and LIST-ALL-ELEMENTS.

Handle any incorrectly formulated commands with an appropriate error message.

Part B:  Create a Java applet that accepts commands that operate a set of traffic lights at an intersection.  Use the "TRAFFIC" ADT defined as follows.   Note that an important part of the assignment is for each team to interpret the description of the ADT.  Each team should work alone on this interpretation and develop the skill to understand such a description.

   Data: A seven-state counter called PHASE. It contains a value from the set {0,1,...,6}
         A flag w whose value is in the set {true, false}.  When it is true, it means that the walk button was pressed
         during the current cycle and so the walk light should be shown a the end of this cycle.
 
  Operations:  { NEXT-PHASE,  PRESS-WALK-BUTTON}

         NEXT-PHASE: {0,1,...,6} X {true,false} -> 
                {0,1,...,6} X {true,false} X {red, yellow, green} X {walk, don't walk} X  {red, yellow, green} X {walk, don't walk}
         NEXT-PHASE: n |->  if w and n=5 then (6,false,red,walk,red,walk);
                       else if  n=5 then (1,w,red,don't walk, green,don't walk);
                       else if  n=6 then (0,w,red,don't walk, red, don't walk);
                       else if  n=0 then (1,w,red,don't walk, green,don't walk};
                       else if  n=1 then (2,w,red,don't walk, yellow,don't walk};
                       else if  n=2 then (3,w,green,don't walk, red,don't walk};
                       else if  n=3 then (4,w,yellow,don't walk, red,don't walk};
                       else if  n=4 then (5,w,red,don't walk, green,don't walk};

        PRESS-WALK-BUTTON: {0,1,...,6} X {true,false} -> {0,1,...,6} X {true,false}
        PRESS-WALK-BUTTON: (count,w) |-> (count,true)

After you get the basic functionality working, enhance your applet with a graphical representation of two traffic lights and walk/don't walk signs, and display the changes to the lights whenever the NEXT-PHASE command is given.

Partnership Work:  This assignment requires partnership work.  Work in teams of 2.  Form your team BEFORE you do Part A.