Homework 5 (Baby Names) FAQ

Q: How do I get started?

A: Read Ch. 6 in the textbook. Look over the IMDB movie example from lecture.

Q: How do I make my code work for the 0 case?

A: The 0 ranking case is one of the hardest parts of the assignment. We recommend getting everything else to work first before worrying about the 0 case. You'll need to insert code to handle 0 differently than other rankings. One hint: A ranking of 0 is really more like a ranking of 1000, so it may help you to treat it that way in parts of your code.

Make sure to avoid redundant code. If you're doing the same thing in many branches of an if/else, that's redundant. It will make your code harder to write and more likely to have bugs.

Q: Why do I get a NoSuchElementException?

A: You tried to read past the end of a Scanner. Read the exception output text carefully and look for the first line that mentions your program. That's the line that is the culprit. For example, the output:

Exception in thread "main" java.util.NoSuchElementException
			          at java.util.Scanner.throwFor(Scanner.java:838)
			          at java.util.Scanner.next(Scanner.java:1347)
			          at BabyNames.sillyMethod(BabyNames.java:39)
			          at BabyNames.main(BabyNames.java:15)
			

means that there's an error in sillyMethod at line 39 of BabyNames.java.

Q: Why do I get an InputMismatchException?

A: You tried to read the wrong type of token from a Scanner. For example, you tried to read the word "Lisa" as an int.

Q: How do I make a Scanner start over or go back?

A: You can't! But if it is a String Scanner, you can make a new Scanner over the same String to start reading over again.

Q: Why are my coordinates wrong? How can I fix them?

A: Try using the debugger or println statements to see what they are.

Q: There are some names that are found in meanings.txt but not in names.txt. What should I do in such a case?

A: Treat it as the name-not-found case. Print the error message and don't display any rankings or meaning data.

Q: Why does my program give a weird error message like the following when I run it on my Mac?

2008-11-12 20:37:21.839 java[372] CFLog (0): CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port = 0x10303, name = 'java.ServiceProvider'
			See /usr/include/servers/bootstrap_defs.h for the error codes.
			2008-11-12 20:37:21.840 java[372] CFLog (99): CFMessagePortCreateLocal(): failed to name Mach port (java.ServiceProvider)
			

A: It's some sort of Mac/Java bug. It's not anything wrong in your code. You may safely ignore it.