YCP Logo Assignment 3: Go Fish

Due: Friday, October 10th by 11:59 PM

Your Task

Implement the card game Go Fish for two human players.

The game starts by shuffling the deck, and dealing 5 cards to each player. The players then alternate turns.

On each player's turn, the game should ask him/her for the rank of a card to ask for. If the other player has any cards of that rank, they are transferred to the current player's hand. If the other player does not have any cards of that rank, the current player must "Go Fish" by drawing

If, at the end of the turn, a player has four cards of the same rank, they form a book, and are removed from the player's hand. The game ends when the deck is empty: the player with the greatest number of books wins.

Here are some excepts of an example session (click the link to see the full output):

It's player 1's turn
Your hand:
FOUR of CLUBS
ACE of DIAMONDS
SEVEN of HEARTS
ACE of HEARTS
FIVE of SPADES
Rank to ask for:
ACE
Go Fish!
You drew a QUEEN of CLUBS

It's player 2's turn
Your hand:
SEVEN of CLUBS
EIGHT of CLUBS
JACK of CLUBS
THREE of DIAMONDS
FOUR of HEARTS
Rank to ask for:
JACK
Go Fish!
You drew a NINE of DIAMONDS

It's player 1's turn
Your hand:
FOUR of CLUBS
QUEEN of CLUBS
ACE of DIAMONDS
SEVEN of HEARTS
ACE of HEARTS
FIVE of SPADES
Rank to ask for:
FOUR
You took 1 FOUR(s)

It's player 2's turn
Your hand:
SEVEN of CLUBS
EIGHT of CLUBS
JACK of CLUBS
THREE of DIAMONDS
NINE of DIAMONDS
Rank to ask for:
EIGHT
Go Fish!
You drew a TWO of CLUBS
...game continues...

The program should indicate when a player completes a book of four cards of the same rank:

It's player 2's turn
Your hand:
EIGHT of CLUBS
JACK of CLUBS
SEVEN of DIAMONDS
JACK of DIAMONDS
KING of DIAMONDS
THREE of HEARTS
FIVE of HEARTS
SIX of HEARTS
JACK of HEARTS
KING of HEARTS
FIVE of SPADES
QUEEN of SPADES
Rank to ask for:
SIX
Go Fish!
You drew a JACK of SPADES
You made a book (or books)!
4 JACKs

The game ends when there are no more cards in the deck. The program should determine which player has more books, and announce the winner of the game:

It's player 1's turn
Your hand:
Rank to ask for:
THREE
Go Fish!
You drew a TWO of DIAMONDS

Final scores:
Player 1: 5 books
Player 2: 7 books
Player 2 wins!

Getting Started

Use your solution to Lab 9 as a starting point. Make a copy of that project, renaming it to CS201_Assign3.

Hints

Use classes to represents players, hands, cards, and the deck. Use enum types to represent suits and ranks.

Use ArrayList objects to store lists of items such as cards (in a player's hand, in the deck, etc.) Don't forget to specify an element type (e.g., ArrayList<Card> for an ArrayList of Card referneces.)

You can convert a string containing the name of an enum value into an actual enum value using the enum type's valueOf(String) method. For example, reading a rank from the keyboard and converting it into a member of the Rank enum type:

String rankStr = keyboard.next();
try {
        Rank r = Rank.valueOf(rankStr.toUpperCase(Locale.US));
        return r;
} catch (IllegalArgumentException e) {
        System.out.println("Not a valid rank - please try again");
}

Note that valueOf will throw an IllegalArgumentException if the string is not the name of an enum value.

Grading Criteria

Fully completing the assignment as described above will earn a maximum grade of 90.

Of the above 90 points, 20 will be awarded on the basis of how well the program uses classes. (For example, if your entire program is a single main method, the maximum possible grade is 70.)

Points may be deducted for poor coding style.

Extra credit

For up to 10 points of extra credit, implement the program so that the human player plays against a computer opponent.

For up to 10 points of extra credit, implement a GUI.

Submitting the project

Export your project as a zip file (File->Export...->Archive File) and upload it to the submission server as assign3. The URL of the server is

https://camel.ycp.edu:8443/