-
Q: Where do I start????
-
A: Read the write-up in its entirety. Try to develop the program in stages, and focus on the text-only output. Start on the graphics part only after you have the text output correct. Review example programs from section (randomX and comparePoints) and lecture (Sentinel.java and .java).
-
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(). Do NOT use .nextLine()
-
Q: How do I draw a single pixel?
-
A: 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: 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.
-
Q: How do I compute the best walk (fewest steps)?
-
A: You mostly have to figure this out for yourself, but here are some hints. In each walk you should keep track of how many steps were needed. You should probably also keep track of the best walk you have seen so far, and update that value accordingly after every game, if the walk is better than the best one seen previously. You will have to carefully manage your returns and parameters to make sure that the right information reaches the right parts of your code.
-
Q: Is it okay to have a method that calls itself? Or to have a Method A that calls Method B, which calls A, which calls B, ...?
-
A: No, you should not do this on Homework 5. Having a method call is a real computing technique called recursion. Recursion is not an appropriate algorithmic technique for solving this problem. You should solve the problem correctly using while
loops for repetition, instead of recursion.