Tuesday October 9: Compiler doesn't want an argument!
Question: When I use the
nextInt(n)
method of the Random
class
(n
is an int
, exactly as shown in the
hand-out), the compiler complains there are too many arguments.
What's going on, and how do I fix it?
Answer: This method was added to JDK 1.2, so
older versions don't have it. However, the closely-related
method nextInt()
(no argument) is supported in
older versions. This method returns a random integer in the
entire int
range, so you'll need something like
(assuming that n
and randInt
are
integers, and random
is a Random
object):
randInt = Math.abs(random.nextInt()) %
n;
Monday October 8: Too well jumbled?
Question: What if my jumbled word is the same as my original word? Do I have to check for, and exclude, this possibility?
Answer: No. So long as you generate the original word randomly, it is a valid jumble. It may even stump the user, since she/he may well not be expecting the jumble to be the same as the original.
Monday October 8: Not very random!
Question: I tried using the Random class, and I instantiated a new random object every time I used it. The result doesn't look very random: I get clusters of the same integer.
Answer: You should only instantiate one Random object per class. Think of your Random object as an infinitely deep barrel of random numbers. You keep fishing numbers out of the same bin --- you don't need to create new bins so that you can fish one from each.
Friday October 5: Comparing strings
Question: How should I compare strings to determine whether the user's guess is correct?
Answer: Try looking at Jim Clarke's explanation of this question.
Friday October 5: Which case should I use?
Question: If the user enters a list of four-letter words, should I make sure they are all upper case?
Answer: You have complete creative control here, since the specification doesn't mention this. You can treat the alphabet as though it has 52 letters (distinct upper and lower), so the word "real" is different from "rEaL" etcetera. Or you might find a suitable method for making everything the same case.
Monday October 1: Loops, ifs, and such
Question: Did you really mean we couldn't use any loops or conditional statements (e.g. if statements)?
Answer: Yes. This assignment uses only material
you've learned so far, plus the Random
class. This
means that you can't print out an English response to user guesses based
on some condition. But, you can return boolean values true
or false
where these are appropriate.
Monday October 1: Testing
Question: You say to implement and test each class we design separately. How do we test them?
Answer: Write another class (no need to submit it)
with a main
method that creates an instance or two
of the class you're testing and test drives it.
Monday October 1: Example session
Question: Can you give me an example of how a typical session should look?
Answer: No --- each person's solution will be different, so the word "typical" doesn't really apply.
Monday October 1: A good guesser
Question: What if the user guesses the correct word on guess number 1? Wouldn't I need a conditional statement to finish early?
Answer: No. A good guesser can simply make three correct guesses, or mix correct and incorrect guesses for variety.