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 – Lecture #22 to #24: Guess? Java

The twenty-second lecture starts by explaining the features of the next assignment #6. The theoretical part explains containers and data structures, and finishes showing how to pars a file to extract its data.

Prerequisites to the twenty-third lecture is reading chapters 12.1 through 12.3 of “Art and Science of Java”. The lecture discusses searching and sorting.

The twenty-fourth lecture continues with collections and introduces programming patterns.

Code for these lectures are available on github.

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

cs106a – Assignment #5

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

Because this assignment is meant to teach arrays it uses them heavily. Thus create arrays to hold the values of the last roll of dice, to hold the categories which have already been used, and to hold to total and the sub scores. Because they are needed in several methods create them as instance variables. The dice array is filled with each (first) roll thus it can be initialized with the declaration. The others are instancialized and thus reset starting a new game. The array holding the used categories differs from the others as it is two dimensional where the rows represent the player and the columns the selected category.

The game itself consists of a fixed number of rounds which equals the number of scoring categories. In every round each player has a fixed number of rolls where the first one differs slightly from the following as all dice have to be rolled. After a players turn his/her score has to be updated, and at the end of the game the winner has to be selected.
Continue reading “cs106a – Assignment #5”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail