Java 2 with Mr. Merlis - The Walker Project

 

 

Walker 1  Getting Walker to move and displaying locations visited

 

WalkerApp is the test program for the Walker class.  Finish all the methods in Walker except the displayData method.  Run the application program.  Paste your output below the main and label it “Output for Walker 1”.

 

It should look something like this:

 

/*       Output for Walker 1

2          3          4          5          4          5          4          3          2          1         

2          1          0          1          2          1          0          -1         0          -1        

0          1          2          3          2          1          2          3          4          5         

4          5          6          7          6          7          6          5          6          7         

8          7          6          7          8          7          6          7          6          7         

 

The farthest from the starting point is 6

 */


Walker 2.  Displaying the data collected in move()

 

Create a NEW APPLICATION PROGRAM.
Copy the code from the first app. and change it to look like below:

 

public class WalkerApp2

{

    public static void main (String[] args)

    {

        Walker sleepy = new Walker(50);

        sleepy.displayMoves(50);

        sleepy.displayData();           

    }

}

 Complete the one method, displayData, by using the integer array, itsTravels, as a private instance variable.  The index of an array element will represent the Walkers position and the contents of the array at that index will represent how many times the Walker has visited that location.  For example, if you start your Walker at position 7,and make the following moves, the array will change as noted.

 

      [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

start 0   0    0   0    0    0   0    1   0    0     0      0     0      0      0                        

 

     [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

left 0   0    0   0    0    0   1    1   0    0     0      0     0      0      0 

 

     [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

left 0   0    0   0    0    1   1    1   0    0     0      0     0      0      0 

 

     [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

right 0  0    0   0    0    1   2    1   0    0     0      0     0      0      0 

 

     [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

left 0   0    0   0    0    2   2   1   0    0     0      0     0      0      0 

 

 display moves should look like this

 

  position     times visited

 

   5               2

   6               2

   7               1

 

  It should not show any positions for which the contents are zero.

 


Walker 3. Drawing your Walker       50 points

 

WalkerApplet is the container for the Walker graphics project.  Add a new constructor to your Walker class that will take a Graphics2D object as the first parameter.  Give the Walker

a new private instance variable p (for page) that is also  a Graphics2D object.  We will discuss in class how to reference the figure to a location on the page and then add complexity with other methods.

 


 Walker 4.  Animating your walker and adding a background.  30 points

 

To animate your walker you need to pause after each move and then cover the picture with a new background and draw your walker again.  To begin use the background method below(put it at the bottom of the Walker class).  When your walker is moving make a background scene.

 

public void drawBackground()

{

        p.setColor (Color.white);

        p.fillRect (0, 0, 1000, 1000);  // clear area, use your own dimensions

 }

 


Extra Credit.  Up to 50 + points

 

Have the Walker move in two dimensions (add itsYPosition) +5 (or 3-D with scaling)

Adding another moving object that is independent of your original +10

            have the object race or chase

            collect stats on number of collisions, farthest apart, average distance

Using more than one view (right/left facing)  +5 – 10 depending on complexity

Moving parts (legs, arms, etc)

Your own ideas, please have them okayed before starting them.

Use of shading or random colors for special effects