CS 307Assignment, Baby Names

Programming Assignment 4: You must complete this assignment on your own. You may not discuss their work with anyone except the instructor and other members of the instructional staff (TA or proctor). You may not acquire, from any source (e.g., another student or an internet site), a partial or complete solution to a problem or project that has been assigned. You may not show another student your solution to an assignment. You may not have another person (current student, former student, tutor, friend, anyone) “walk you through” how to solve an assignment. Review the class policy on collaboration from the syllabus.

The purposes of this assignment are:

  1. to work with ArrayLists
  2. to implement a program that uses multiple classes. (object based programming)
  3. to practice processing input
  4. to practice implementing individual classes based on a given specification

In this assignment you will implement a program that is a series of 3 classes. One of the classes, NameSurfer.java, is the driver program and is a procedural program rather than a true class. The other two classes, NameRecord and Names are true classes. (In other words they each define a new data type.) The purpose of the program is to allow someone to search a database of popular baby names by decade for the past 11 decades. NameRecord will store the information for a single name and its popularity during the past 11 decades. Names will store a large number of NameRecords in an ArrayList. NameSurfer will interact with a Names object and some NameRecord objects. I am giving you most of the design of the program. You just have to complete the implementation

Files:

  File Responsibility
Source Code NameSurfer.java Provided by me and you
Source Code NameRecord.java Provided by you.
Source Code Names.java Provided by you.
data file

names.txt

Provided by me.
sample run log nameSurferLog.txt Your output should match this example. Provided by me.
Submission NameSurfer.java, NameRecord.java, and Names.java Provided by you

Description: This assignment is based on an assignment created by Nick Parlante and Stuart Reges' version of the assignment..

Complete a program that allows a user to query a data base of the 1000 most popular baby names in the United States per decade for th past 11 decades under the constraints of the General Assignment Requirements and as described below. As always, you may add helper methods and should do so to provide structure to the program and reduce redundancy. One additional constraint: You must use the ArrayList class in the solution as discussed below. You are encouraged to use methods from the ArrayList class and String class to make the program easier to write. The ArrayList class has lots of methods that can make your job easier and one of the goals of this assignment is to learn those methods. Don't try to do everything "by hand" with the get method and loops. Make use of the methods in ArrayList.

Your program will be processing a file with data obtained from the Social Security Administration.  They provide a web site showing the distribution of names chosen for children over the last 100 years in the US (www.ssa.gov/OACT/babynames/).

The data represent the 1000 most popular boy and girl names for kids born in the US going back to 1900. The data can be boiled down to a single text file as shown below. On each line we have the name, followed by the rank of that name in 1900, 1910, 1920, ..., 2000 (11 numbers). A rank of 1 was the most popular name that year, while a rank of 997 was not very popular. A 0 means the name did not appear in the top 1000 that year at all.  The lines are in alphabetical order.

...
Sam 58 69 99 131 168 236 278 380 467 408 466
Samantha 0 0 0 0 0 0 272 107 26 5 7
Samara 0 0 0 0 0 0 0 0 0 0 886

Samir
0 0 0 0 0 0 0 0 920 0 798
Sammie 537 545 351 325 333 396 565 772 930 0 0
Sammy 0 887 544 299 202 262 321 395 575 639 755
Samson 0 0 0 0 0 0 0 0 0 0 915
Samuel 31 41 46 60 61 71 83 61 52 35 28
Sandi 0 0 0 0 704 864 621 695 0 0 0
Sandra 0 942 606 50 6 12 11 39 94 168 257
...

Note,  a 0 in the data file means the name was not ranked in the top 1000 for the corresponding decade. It has some unknown rank greater than 1000. When you store a 0 from the data file in your NameRecord objects you may use something other than 0 if you think it will make your algorithms easier to implement. (Recall altering the way data is stored to fit our needs is part of the magic of programming.)

We see that “Sam” was #58 in 1900 and is slowly moving down. “Samantha” popped on the scene in 1960 and is moving up strong to #7. “Samir” barely appears in 1980, but by 2000 is up to #798. The database is for children born in the US, so ethnic trends show up when immigrants have kids.

You will be provided with one class, NameSurfer.java. This is the main driver class. When this class's main method is called it opens a window to pick the file with the names in it. The file is called names.txt. After creating the database of names encapsulated in a class called Names.java the program displays a menu and allows the user to make various queries of the database. The provided version of names shows five of the options and you will add two more.


Suggested steps for implementing the program.

0. These suggested steps describe implementing the requirements. You may add methods of your own if you want. Also you may store data differently. The files uses a 0 to indicate the name had a rank greater than 1000 for a given decade. You can store a value other than 0 if you want. (The value for "not ranked in a given decade" is on the other side of the wall of abstraction.)

1. Implement and test the class called NameRecord. Objects of this type store the data for an individual name, including the name itself (a String) and the rank of the name for each of the 11 decades. The ranks for each decade must be stored in an ArrayList of Integers. The class should have the following properties (you may add more methods if you wish):

After completing all these methods you should thoroughly test the NameRecord class using individual lines from the names.txt file or with your own data. Include your testing code in your NameSurfer class even though it will not be called when the program is run. Part of the assignment grade will be based on the tests you write for the NameRecord class.

2. Implement and test the Names class. This class stores all of the NameRecord objects in an ArrayList. This class must have the following methods.

3. Complete the methods in the NameSurfer class and make changes to the menu to include the three options that are not yet present.

The menu choices are:

1 to search for names.
2 to display data for one name.
3 to display all names that appear in only one decade.
4 to display all names that appear in all decades.
5 to display all names that are more popular in every decade.
6 to display all names that are less popular in every decade.
7 to perform the method of your own design from your Names class
8 to quit

For expected program behavior review the sample run log. Your output shall match that of the sample run log for the various operations, except that you will not trim the output for operations that results in a large number of names. (Show them all!)

4. Neat searches. This is an interesting application because when your program is finished you can investigate various trends in naming children. In a comment at the top of the file discuss one interesting trend you found. Here are some examples. (You may not use these as your interesting trend.)

Nick got the idea for this assignment from an article by Peggy Orenstein of the New York Times, Where have all the Lisas Gone?


Submission: Fill in the header for NameSurfer.java. Replace <NAME> with your name. Note, you are stating, on your honor, that you did the assignment on your own, as required. If you do the extra work suggested below submit the DrawPanel.java class as well!

When finished turn in the NameSurfer.java, Names.java, and NameRecord.java files using the turnin program. If you add the graphical output turnin in the DrawingPanel class as well.

Checklist: Did you remember to:


Extra: (No extra points, just good karma.)

If you are looking for something fun and extra to do, add a feature to name surfer so that when the user searches for information on a single name (option 2) a DrawingPanel is created with a simple line graph showing the ranking of the name over time. It is often easier to interpret visual information. Here is an example:

Use the DrawingPanel class. (This is a non-standard Java class with various methods for drawing lines.) Strings can be added to the window by getting the Graphics object and using the drawString method. If you use this class be sure to turn in DrawingPanel with your other files.

  Back to the CS 307 homepage.