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

cs106a – Assignment #6 – Task #1

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

Assemble the GUI interactors

If you look at the bottom of Figure 1, you will see that the region along the SOUTH edge of the window contains several interactors: a JLabel, a JTextField, and three JButtons. Since putting up interactors is something you haven’t done in previous assginments, you probably want to work on this step before it becomes complicated with all the other parts of the assignment. Thus, your first milestone is simply to add the interactors to the window and create an implementation for the actionPerformed method that allows you to check whether you can detect button clicks and read what’s in the text field.
The simplest strategy to check whether your program is working is to change the definition of the NameSurfer class so that it extends ConsoleProgram instead of Program, at least for the moment. You can always change it back later. Once you have made that change, you can then use the console to record what’s happening in terms of the interactors to make sure that you’ve got them right. For example, the figure below shows a possible transcript of the commands used to generate the output from Figure 1, in which the user has just completed the following actions: Continue reading “cs106a – Assignment #6 – Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #6 Extra Task #3

Please note, this blog entry is from a previous course. You might want to check out the current one.

Let the user search inside the tags table view. This is a non-trivial extra credit exercise, but you’ll definitely want to use NSSearchBarController.

During a search we will adjust the predicate of the fetched results controller using a new private property:

@property (nonatomic, strong) NSPredicate *searchPredicate;
...
@synthesize searchPredicate = _searchPredicate;
...
- (void)setupFetchedResultsController
{
...
    request.predicate = self.searchPredicate;
...
}

Continue reading “Assignment #6 Extra Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #6 Extra Task #2

Please note, this blog entry is from a previous course. You might want to check out the current one.

Allow users to reorder their itinerary for their vacation. To do this, you might want to think about creating a top-level Entity (Itinerary) in your schema and using an “ordered to-many relationship” to store the places in the itinerary. An “ordered to-many relationship” appears in your code as an NSOrderedSet (instead of an NSSet). The table view that shows the places in the itinerary will have to be rewritten to display this NSOrderedSet of places (it won’t be able to be an NSFetchedResultsController-based table view) and you will have to figure out how to use UITableView API to edit an NSMutableOrderedSet. Warning: while this is not that difficult to implement coding- wise, it requires quite a bit of investigation to figure out. Another approach is to add an attribute in your schema that determines the order (but this can be a little bit clunky). The former approach will probably lead to more learning opportunities.

Following the instructions from above create a new Entity called “Itinerary” for the Core Data Model with a ordered one-to-many relationship called “places” on the Itinerary side and “itinerary” on the place side. Recreate all NSManagedObject subclasses and add a category for the Itinerary class.
Continue reading “Assignment #6 Extra Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail