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

cs106a – Assignment #5 – Extra Task #3

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

Beef up your Yahtzee to the variant called “Triple Yahtzee.”

In this variant, each player manages three simultaneous scorecard columns, as if they were playing for three players at once. The player can assign a roll to any one of their three columns. All entries are scored normally with respect to categories and validity, but the values in the second column are doubled, and the third column values are tripled. The player’s score consists of the sum of all three columns. This would make for a three- dimensional array (an array of players who have any array of columns which are an array of score entries)—pretty tricky! Game play continues for 3*13 rounds, until all players have filled in all entries in all three columns. The player with the highest total score is the winner

The display needs to additional cols with suiting names to be able to hold the additional scores:
Continue reading “cs106a – Assignment #5 – Extra Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #5 – Extra Task #2

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

Incorporate the bonus scores for multiple Yahtzees in a game

As long as you have not entered a 0 in the Yahtzee box, the rules of the game give you a bonus chip worth 100 points for each additional Yahtzee you roll during the same game.

Start by a new array as instance variable which indicates if additional Yahtzees are allowed – meaning it was not set to 0 before – and initialize it:
Continue reading “cs106a – Assignment #5 – Extra Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #5 – Extra Task #1

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

Add a high score feature

Save the top ten highest scores and names to a file and make it persistent between runs of the program. Read the file when you start and print out the hall of fame. If a player gets a score that preempts one of the early high scores, congratulate them and update the file before you quit so it is recorded for next time.

Add a new method to display the high scores:
Continue reading “cs106a – Assignment #5 – Extra Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail