Homework 6 (NameSurfer) FAQ

Q: Why is it that all of my calculations in NameGraph come out with a result of 0?
A: A common bug here is integer division; for example, 147 / 2000 equals 0 in Java. See also the next question about drawing from init vs. run.
Q: Why is it that my NameGraph appears with no grid lines in it, but then later when I search for a name, the grid lines appear?
A: One annoying quirk of the Stanford libraries is that the getWidth and getHeight methods return 0 if you call them from init. So if you are initializing the state of your NameGraph in your NameSurfer's init method and drawing lines on it at that time, they won't draw in the right place. The issue doesn't occur if you check for the width or height in your run method. Your name graph is supposed to have an update method that redraws the graph, so try calling that from your NameSurfer's run method.
Q: The problem spec says I am supposed to use a HashMap to store the names in my database. But I don't understand how to use it or why it is helpful.
A: A HashMap allows you to quickly search for something based on a "key" piece of information. Our intention is that you would create a map where the keys are baby names and the values are Person objects representing the person with that name. Gender matters, so you'll have to think about how to incorporate gender into your map(s) properly.
Q: Is it possible for the same name to appear for both genders? Do I have to handle this in my code?
A: Yes, that absolutely can happen, and yes, you need to handle it. A good test case is the name "Morgan", which is popular for both boys and girls. How to handle this issue? Well, you'll have to think of a way to keep boy data separate from girl data, or at least a way to disambiguate the two when the user stores or searches for a name later.
Q: Why does my program crash with an "out of memory error" when running it with the large ranks.txt file?
A: That file is a gigantic data set. It causes your program to create a ton of Person objects to put into the database. So if you are wasting any memory in the Person object, the issue is compounded to a great degree. Don't store any unnecessary data fields in each Person; for example, don't store a Scanner as a field. Some students report better performance when they change the data structure being used inside the Person class, too.
This document and its content are copyright © Marty Stepp, 2014. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.