cs106a – Assignment #6 – Extra Task #3

The complete specification of assignment #6 can be found as part of the stream at iTunes.

Try to minimize the overprinting problem

If the popularity of a name is improving slowly, the graph for that name will cross the label for that point making it harder to read. You could reduce this problem by positioning the label more intelligently. If a name were increasing in popularity, you could display the label below the point; conversely, for names that are falling in popularity, you could place the label above the point. An even more challenging task is to try to reduce the problem of having labels for different names collide, as they do for Sam and Samantha.

For the first task – moving the label below the graph if is ascending – the label drawing class needs more information about the graph thus it is better to provide the complete entry instead of the name and rank only:
Continue reading “cs106a – Assignment #6 – Extra Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #6 – Extra Task #2

The complete specification of assignment #6 can be found as part of the stream at iTunes.

Allow deletion as well as addition

Because the screen quickly becomes cluttered as you graph lots of names, it would be convenient if there were some way to delete entries individually, as opposed to clearing the entire display and then adding back the ones you wanted. The obvious strategy would be to add a Delete button that eliminated the entry corresponding to the value in the Name box. That approach, however, has a minor drawback given the design so far. If you added a bunch of entries to the graph and then deleted the early ones, the colors of the later entries would shift, which might prove disconcerting. Can you redesign the color-selection strategy so that displayed entries retain their color even if other entries are removed?

Add the delete button to the main class:
Continue reading “cs106a – Assignment #6 – Extra Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #6 – Extra Task #1

The complete specification of assignment #6 can be found as part of the stream at iTunes.

Add features to the display

The current display contains only lines and labels, but could easily be extended to make it more readable. You could, for example, put a dot at each of the data points on the graph. Even better, however, would be to choose different symbols for each line so that the data would be easily distinguishable even in a black-and-white copy. For example, you could use little circles for the first entry, squares for the second, triangles for the third, diamonds for the fourth, and so on. You might also figure out what the top rank for a name is over the years and set the label for that data point in boldface.

Create a new data type to hold the possible forms of the markers:
Continue reading “cs106a – Assignment #6 – Extra Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #6 – Task #5

The complete specification of assignment #6 can be found as part of the stream at iTunes.

Complete the implementation of NameSurferGraph class

In addition to creating the background grid, the update method in NameSurferGraph also has to plot the actual data values. The NameSurferGraph class includes two methods for specifying what entries are displayed on the screen. The addEntry method adds a new NameSurferEntry to a list of values that are currently on the display. The clear method deletes all of the entries in that list so as to clear the graph.
There are a couple of points that you should keep in mind while implementing this part of the program:

  • To make the data easier to read, the lines on the graph are shown in different colors. In the sample applet on the web site, the first data entry is plotted in black, the second in red, the third in blue, and the fourth in magenta. After that, the colors cycle around again through the same sequence.
  • The fact that rank 1 is at the top of the window and rank 1000 is at the bottom means that it can sometimes seem confusing that rank 0—which means that the name does not appear in the top 1000 values for that year—appears at the bottom. To reduce the apparent discontinuity between rank 1 and rank 0, the entries for names that are absent from the data for a decade are listed with an asterisk instead of a numeric rank.

Continue reading “cs106a – Assignment #6 – Task #5”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #6 – Task #4

The complete specification of assignment #6 can be found as part of the stream at iTunes.

Create the background grid for the NameSurferGraph class

The next step in the process is to begin the implementation of the NameSurferGraph class, which is responsible for displaying the graph in the window by building the underlying model.
There are a couple of important items in the NameSurferGraph starter file that are worth noting:

  1. This class extends GCanvas, which means that every NameSurferGraph object is not only a GCanvas but also an instance of all the superclasses of the GCanvas class. GCanvas is a subclass of Component in the standard java.awt package and therefore is part of the hierarchy of classes that can be added to the display area of a program. Moreover, it means we can call any of the GCanvas methods, such as adding or removing GObjects, from within NameSurferGraph.
  2. Continue reading “cs106a – Assignment #6 – Task #4”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #6 – Task #3

The complete specification of assignment #6 can be found as part of the stream at iTunes.

Implement the NameSurferDataBase class

The next step in the process is to implement the NameSurferDataBase class, which
contains two public entries:

  • A constructor that takes the name of a data file and uses that to read in the entire set of data from the file into internal data structures that allow the class to keep track of all the records as a database.
  • A findEntry method that takes a name, looks it up in the stored database, and returns the NameSurferEntry for that name, or null if that name does not appear.

The code for this part of the assignment is not particularly difficult. The challenging part lies in figuring out how you want to represent the data so that you can implement the findEntry method as simply and as efficiently as possible.
To test this part of the program, you can add a line of code or two to the NameSurfer program so that it creates the NameSurferDataBase and then change the code for the button handlers so that clicking the Graph button looks up the current name in the data base and then displays the corresponding entry (using its toString method).

Continue reading “cs106a – Assignment #6 – Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #6 – Task #2

The complete specification of assignment #6 can be found as part of the stream at iTunes.

Implement the NameSurferEntry class

The NameSurferEntry class encapsulates the information pertaining to one name in the database. That information consists of two parts:

  1. The name itself, such as “Sam” or “Samantha”
  2. A list of 11 values indicating the rank of that name in each of the decades from 1900
    to 2000, inclusive

The class definition begins with a constructor that creates an entry from the line of data
that appears in the NamesData.txt file. For example, the entry for Sam looks like this:

Sam 58 69 99 131 168 236 278 380 467 408 466

The idea behind the design of this constructor is that it should be possible to read a line of data from the file and then create a new entry for it using code that looks like this:

String line = rd.readLine();
NameSurferEntry entry = new NameSurferEntry(line);

Continue reading “cs106a – Assignment #6 – Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail