Java 2 with Mr. Merlis - The Walker Project
WalkerApp is the test program for
the
It should look something like this:
/* Output for
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
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)
{
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
[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.
WalkerApplet is the container for
the
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.
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
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
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