Unformatted text preview:

Math 121: Introduction to Computing Handout#??Assignment #6—NameSurferThe NameSurfer assignment was created by Nick Parlante, who also wrote parts of this handout.Due: Monday, December 11This assignment has two primary goals. The first is to give you an opportunity to useJava interactors to create an application that looks more like a modern interactiveprogram complete with buttons, text fields, and a resizable graphical display. The secondgoal is to pull together the various facilities you have learned about so far to create aninteresting application that—unlike Breakout, Hangman, Yahtzee, and Adventure—is nota game but rather a useful program that enables you to think about sociological questions.Overview of the NameSurfer projectAgainst all bureaucratic stereotypes, the Social Security Administration, provides a neatweb site showing the distribution of names chosen for kids over the last 100 years in theUnited States (http://www.ssa.gov/OACT/babynames/). Every 10 years, the data givesthe 1000 most popular boy and girl names for children. The data can be boiled down to asingle text file that looks something like this:names-data.txt. . .Sam 58 69 99 131 168 236 278 380 467 408 466Samantha 0 0 0 0 0 0 272 107 26 5 7Samara 0 0 0 0 0 0 0 0 0 0 886Samir 0 0 0 0 0 0 0 0 920 0 798Sammie 537 545 351 325 333 396 565 772 930 0 0Sammy 0 887 544 299 202 262 321 395 575 639 755Samson 0 0 0 0 0 0 0 0 0 0 915Samuel 31 41 46 60 61 71 83 61 52 35 28Sandi 0 0 0 0 704 864 621 695 0 0 0Sandra 0 942 606 50 6 12 11 39 94 168 257. . .Each line of the file begins with the name, followed by the rank of that name in each ofthe 11 decades since 1900, counting the current one: 1900, 1910, 1920, and so on up to2000. A rank of 1 indicates the most popular name that year, while a rank of 997indicates a name that is not popular at all. A 0 entry means the name did not appear inthe top 1000 names for that year and therefore indicates a name that is even less popular.– 2 –The elements on each line are separated from each other by a single space. The lineshappen to be in alphabetical order, but nothing in the assignment depends on that fact.As you can see from the small excerpt from the file, the name Sam was #58 in the firstdecade of the 1900s and is slowly moving down. Samantha popped on the scene in the1960s (possibly because Bewitched ran on television during those years) and is movingup strong to #7. Samir barely appears in the 1980s, but by the current decade is up to#798. The database counts children born in the United States, so trends in particularnames tend to reflect the evolution of ethnic communities over the years.The goal of this assignment is to create a program that graphs these names over time,as shown in the sample run in Figure 1. In this diagram, the user has just typedSamantha into the box marked “Name” and then clicked on the “Graph” button, havingearlier done exactly the same thing for the name Sam. Whenever the user enters a name,the NameSurfer program creates a new plot line showing how that name has fared overthe decades. Clicking on the “Clear” button removes all the plot lines from the graph sothat the user can enter more names without all the old names cluttering up the display.Figure 1. Sample run of the NameSurfer programTo give you more experience working with classes that interact with one another, theNameSurfer application as a whole is broken down into several separate class files, asfollows:– 3 –• NameSurfer—This is the main program class that ties together the application. It hasthe responsibility for creating the other objects and for responding to the buttons at thebottom of the window, but only to the point of redirecting those events to the objectsrepresented by the other classes.• NameSurferConstants—This interface is provided for you and defines a set ofconstants that you can use in the rest of the program simply by having your classesimplement the NameSurferConstants interface, as they do in the starter files. TheNameSurferConstants interface therefore has the same role that YahtzeeConstantsdid in Assignment #5.• NameSurferEntry—This class ties together all the information for a particular name.Given a NameSurferEntry object, you can find out what name it corresponds to andwhat its popularity rank was in each decade.• NameSurferDataBase—This class keeps track of all the information stored in the datafiles, but is completely separate from the user interface. It is responsible for reading inthe data and for locating the data associated with a particular name.• NameSurferModel—This class keeps track of what names are currently on the displaybut does not actually display them. Adding names with the “Graph” button or takingthem all away with the “Clear” button updates the NameSurferModel object, whichthen sends a message to a NameSurferViewer object to update the display.• NameSurferViewer—This class is a subclass of GCanvas that displays the graph of thevarious names by arranging the appropriate GLine and GLabel objects on the screen,just as with the various graphical programs you’ve written this quarter.Even though the class structure sounds complicated, the NameSurfer application isabout the same size as Yahtzee. In my implementation, the source files for NameSurfercontain a few more lines, but the code for Yahtzee is actually about 10% larger in termsof the total number of character, not counting comments. Even if the scale of the projectis comparable to the last assignment, the wise course is to start on the assignment soonand keep up with the milestones described in this handout.Milestone 1: Assemble the GUI interactorsIf you look at the bottom of Figure 1, you will see that the region along the SOUTH edgeof the window contains several interactors: a JLabel, a JTextField, and three JButtons.Since putting up interactors is a new idea, you probably want to work on this step beforeit becomes complicated with all the other parts of the assignment. Thus, your firstmilestone is simply to add the interactors to the window and create an implementation forthe actionPerformed method that allows you to check whether you can detect buttonclicks and read what’s in the text field.– 4 –The simplest strategy to check whether your program is


View Full Document

REED MATH 121 - Study Guide

Download Study Guide
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Guide and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Guide 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?