UW CSE logo uw

CSE 142: Computer Programming I, Winter 2008

arrow CSE Home arrow About Us arrow Search arrow Contact Info

Homework 5 (Random Walk) FAQ

Where do I start????
I don't understand the boolean flag.
What is an InputMismatchException? Why does my program give me that error when reading the radius in the second game? Why do I get an empty line of input? etc.
How do I do animation on my walker?
How do I draw a single pixel?
Why is my random walker "thicker" than the one in the expected output? Is this okay?
Why is my animation "choppy"?
How can I return two values from one method?

Q: Where do I start????
A: Read the write-up in its entirety. Try to develop the program in stages, and focus on the debug mode first (with text-only output). Start on the graphics part only after you have the text output correct. Review example programs from section (Q4) and lecture (RandomRectangles2.java and Sentinel.java).
Q: I don't understand the boolean flag.
A: Write the text-version of the program without worrying about the flag at first. Then when you have the text version of the program working, look at RandomRectangles2.java and copy its code for making the "public static final boolean DEBUG" constant: that is the flag.
Q: What is an InputMismatchException? Why does my program give me that error when reading the radius in the second game? Why do I get an empty line of input? etc.
A: You are probably calling the wrong methods on the Scanner. If you want a word back, use .next(). If you want an int back, use .nextInt().
Q: How do I do animation on my walker?
A: After each time you move your walker, call the sleep method on the DrawingPanel (not on Graphics g!). Pass 5 for 5 milliseconds. As this is completely optional, you should do this only after your entire program is otherwise working.
Q: How do I draw a single pixel?
A: There are several ways. The way our sample solution does it is to draw a rectangle of size 1. Something like this:
g.fillRect(x, y, 1, 1);

Q: Why is my random walker "thicker" than the one in the expected output? Is this okay?
A: It's probably thicker because you used drawRect instead of fillRect. No, it's not okay; please change it to fillRect before you turn it in.
Q: Why is my animation "choppy"?
A: Try downloading HW5's version of DrawingPanel.java and using it instead. The older HW3 version wasn't designed to animate as quickly as we're doing in HW5, so it looks choppier.

Note that this issue shouldn't affect your grade if your code is correct, because we'll grade you using the new DrawingPanel.
Q: How can I return two values from one method?
A: You can't. Maybe you have chosen the wrong method structure; for example, maybe the method should pass those two values as parameters to another method, instead of returning them. Or, depending on what values you're trying to return, you may want to consider using an object instead, such as a Point object if you're trying to return a pair of x/y coordinates.