CS 307Assignment, Baby Names
Programming Assignment 3: 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, section leader, or lab 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:
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 | Provided by me. | |
| sample run log | nameSurferLog.txt | Provided by me. |
| Submission | A4.jar | 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 under the constraints of the
General Assignment Requirements and as described
below. (As always, you may add helper methods.) 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 those 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
The data represent the 1000 most popular boy and girl names for kids born in the
...
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
...
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
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.
1. Implement a class called NameRecord. This stores 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):
String as in the file above
and initializes the data for the NameRecord object. How do
you parse the String into the name and the years? You should
either user the split method from the String
class or a Scanner object. If you use the split
method from the String class the statement would be:String[] parsedData = data.split("\\s+"); //data is the input StringString into its individual components using
whitespace as delimiters. The name itself should be in the first element
of the resulting array and the 11 ranks will be in the remaining elements,
although they will be Strings. You will have to convert them
to ints using the
Integer.parseInt method.. Scanner lineScanner = new Scanner( data ); //data is the input
StringScanner object is created you can use the next
method to pull out the name and then the nextInt method to
pull out the ranks. See the Java documentation for more details on the
split method from the String class and
Scanner objects. NameRecord.NameRecords rank for
a given decade. You can use the convention that 1900 is 0, 1910 is 1, and
so forth. In other words the parameter will be between 0 to get the rank
during the 1900s, 1 to get the rank during the 1910s, and so forth.int for this
NameRecords best decade. In other words it returns the decade this name
was most popular, using the most recent decade in the event of a tie. Return
the actual decade such as 1900, 1910, and so forth. Looking at the data
above Samir's was most popular in 2000 while Sandra's best decade was
1940. This method will return 1900, 1910, 1920, or the other valid
decades, not the codes 0, 1, 2, ... In case of a tie, return the most
recent decade. For example if the name "David"'s best rank was number 2
and it occurred in 1950, 1960, and 1980 the method would return 1980, the
most recent decade.0 950 900 875 850 800 750 700 650
600 500 400 are always improving. The ranks 0 0 0 800 850 800
750 700 650 600 500 400 are not always improving. Recall a 0
means the name did not appear in the top 1000 names for that decade. (When
the rank is 0 indicating a name wasn't in the top 1000 in two consecutive
decades we can't really decide one way or another if it improved from one
decade to the next. So we assume it was not getting more popular.)100 150 200 202 250 300 350 400 450 460 0 are always getting
worse. The ranks 100 150 200 202 250 300 350 400 0 0 0
are not always getting worse. 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 the Names class. This class stores all of the
NameRecord objects in an ArrayList. This class
must have the following methods.
Scanner object. The
Scanner object will already be hooked up to the names.txt file. The
constructor will go use the Scanner to go through all the
names in the file and create a NameRecord object for each
one. This can be done with the following code:String line
while( fileScanner.hasNextLine() ){
line = fileScanner.nextLine();
/* create a NameRecord object based on line and add it to the
ArrayList of NameRecord objects */
}ArrayList of NameRecord
objects that contain a given substring, ignoring case. NameRecord whose name is equal
to a given String ignoring case. If there is no
NameRecord that completely matches the given String
return null. ArrayList of Strings
of names that have been ranked in every decade.ArrayList of Strings
of names that have been ranked in only one decade.ArrayList of Strings
of names that have been getting more popular every decade.ArrayList of Strings
of names that have been getting less popular every decade.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
4. Neat searches. This is an interesting application because when your program is finished you can investigate various trends in naming children as well as others. In a comment at the top of the file discuss one interesting trend you found.
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 ArrayProblems.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 include the DrawPanel.java class in your jar as well.
When finished turn in a jar file named A4.jar that contains the NameSurfer.java, Names.java, and NameRecord.java files using the turnin program. jar is a program included in the standard edition of Java loaded on the computers in the Microlab and that you have on your computer if you downloaded Java. See Sun's page for using jar, my tips for using jar, and / or the guide to creating jars in Eclipse.
Ensure you jar the .java files not the .class files.
Checklist: Did you remember to:
NameRecord class?NameRecord class in the NameSurfer class?Names class?NameSurfer class?ArrayList of Integers to store the ranks in the
NameRecord class
and an ArrayList of NameRecords in the Names class to store all the data.Extra: (No extra points juts 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 stadard 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 include
DrawingPanel in your jar file.