Name Popularity Search Tool Based on the Social Security Administration Data in Java

NameSurfer is a tool to search and graph popularity of names based on data provided by the Social Security Administration in the last century. As you can see in the picture, names can be entered in the names field which are graphed either by enter key or the graph button. Graphs are shown on a scale of a thousand. Zero means the name didn’t show up on the thousand most popular names list. One is the most popular and a thousandth is the least popular in the list.

I have made satisfactory progress in the course CS106a. I have learned about the graphics class GObject, BufferedReader class, RandomGenerator class, and, ACM and Java utilities. Interactors were something new in this section of the course. Although I used similar Canvas method in Yahtzee, I am not so sure about subtle difference between the ConsoleProgram and the Program class. As always following the videos and instructions on the assignment sheet pays well in the course of finishing an assignment. A mix of more doing and less theoretical knowledge definitely assuages the boredom of theoretical knowledge. And in due time theory makes more sense.

With the positive energy after Yahtzee, I started implementing NameSurfer as soon as I finished the last assignment. I tend to batch watch the lectures, then read the assignment and then work on it. I improved up on my workflow and started with reading the assignment. A good number of problems were already making sense which resulted in a clean mental picture and basic implementation of the NameSurfer. Some of the methods like BufferedReader to read the names-text file, store information in a HashMap, and store per graph information in an ArrayList, were pretty clear even before the start of the program. Also lectures were making more sense as I was watching them along with implementing the program. I tend to watch a single lecture per day but this time I was watching two lectures per day. As soon as I got done watching four lectures I sat down and worked crazily on the project. I finished it in record two days. And it took me a night of sleep and a 20 minutes next morning to fix some last moment bugs.

toString() didn’t make much sense when I read it the first time. It was very helpful to implement it to make data human readable in NameSurferEntry class. Similar is true for two Integer class methods that I had forgotten about. Both Integer.parseInt(String) and Integer.toString(int) came handy in converting String to int and int to String, respectively. Life would have been much more problematic if I had to parse integers out of a String manually.

Working with five different classes, NameSurfer, NameSurferEntry, NameSurferDataBase, NameSurferConstants, and, NameSurfergraph was interesting. NameSurfer played the role of assembling all other classes in a comprehensive program. I got to use StringTokenizer class in NameSurferEntry Class. It broke down the string into name and year and stored this information in an Array. I broke down the names file in NameSurferDataBase class. Passes single entry in NameSurferEntry to be stored in the array. Then I created a HashMap with template String and NameSurferEntry. Name as a String was used as a key and NameSurferEntry was stored as value.

NameSurferGraph was the trickiest to implement. It took me a whole day to implement it. The NameSurferGraph was to be responsive. The starter package included the code for the responsiveness. ACM graphics aren’t my favorite part. The whole class was written in a very old graphic toolkit. I tend not to mess too much with it. The grid layout was easy to implement with GLine and GLabel. The trick was aligning the graph lines. It took me several trials to get it right. I had clear idea how I was going to do that but implementation could get messed up. There were two important constants, the array had 12 cells and number of decade value were 11. I had to be very picky about when to let the loop run a less, equal or a more than NDECADES. I also decided to restrict the graph between the top and bottom horizontal line which required me to convert the thousand scale to in-between space of the graph. It is always interesting to see the vast difference generated by using int instead of double or a using long mathematical formula in a line.

Implementing colors to cycle between black, red, blue, and magenta was quite mind bending. I thought about various ways to implement it, for examples, using array, loop, if-for statements, etc. None worked as I had thought. In the end, it was as simple as taking a mod of user’s count in the array list by 4 which the number of colors we want to cycle through. I also made sure that empty strings and same names didn’t end up in the array list.

At the end of the day, it was very hard to get anything done when I had myself exhausted but sleeping on it payed well the next day. A fresh mind is what you need to solve the problems of programming.

As always you can check the code in my Github repo.