Course: Introduction to Computers & Programming (JAVA), Summer 2009
Instructor: Christopher Conway

# Homework #6

## Due: Tuesday, 23 June 2009 at 11:59 PM

NOTE: If you choose to request an extension on this homework, your work must be received by Sunday, 28 June at 11:59 PM.
NO WORK CAN BE ACCEPTED AFTER THIS DEADLINE.

Modify the program you submitted for Homework #5 in the following ways:

• Your program must get the names of the 4 players from the command line as an array of Strings, and display the names of the players above the corresponding columns.
• Eliminate the potential of dealing the same card more than once.

Example run:

```Mauro           Howard          Frank           Jim
5 of Diamonds   A of Clubs      K of Spades    10 of Diamonds
10 of Spades     9 of Diamonds   J of Diamonds   7 of Diamonds
J of Clubs     10 of Clubs      7 of Spades     5 of Clubs
Q of Hearts     3 of Diamonds   A of Hearts     3 of Hearts
9 of Spades     K of Diamonds   7 of Hearts     K of Hearts
```

REQUIREMENTS:

• Use an array to keep track of each card that is dealt to a player. You will need a boolean array of size 52 in order to do this. Initially, each element in the array should be initialized to false. As each card in the deck is dealt, an element corresponding to that card will be changed to true.
• A good way to map the array elements to the deck is to use integer division and modulus with your random number (range 0 – 51). What numbers would work well? Hint: There are 13 cards and 4 suits.
• Before printing each card randomly drawn from the deck, your program must first check the array to see if the card has already been dealt. If the card was not previously dealt to a player, your program must display the card and then modify the array to mark the card as being dealt. If the card was already dealt, then your program must pick a new card.

### Extra Credit (5 points):

Revise your solution to Homework #3, including the extra credit, to use the following methods:

• `Character.isLowerCase(char c)` - returns `true` if the character `c` is lowercase; `false` otherwise.
• `Character.isUpperCase(char c)` - returns `true` if the character `c` is uppercase; `false` otherwise.
• `Character.isWhitespace(char c)` - returns `true` if the character `c` is a whitespace character (e.g., a space, a tab, etc.); `false` otherwise.
• `Character.toLowerCase(char c)` - returns the character `c` converted to lowercase.
• `Character.toUpperCase(char c)` - returns the character `c` converted to uppercase.
• ```isWordStartingAtIndex(String sentence, int i, String word)``` - returns `true` if the String `sentence` contains the String `word`, followed by a space, starting at character index `i`.
All of these methods, except the last, are standard Java library methods. `isWordStartingAtIndex()` is defined as follows (copy and paste the definition into your program).
```    /** Returns true is the String sentence contains the String word,
*  followed by a space (or the end of the String), starting at
*  index startIndex.
*/
public static boolean isWordStartingAtIndex(String sentence, int startIndex,
String word) {
int endIndex = startIndex + word.length();
if( endIndex > sentence.length() ) {
/* word is too long to fit in sentence */
return false;
} else {
/* pick out the substring that might match word */
String candidate = sentence.substring(startIndex, endIndex);
/* set match if word and the substring are equal */
boolean match = word.equals( candidate );
/* return true if the next char is the end of the string
* or a whitespace character */
return (endIndex == sentence.length() ? match :
match && Character.isWhitespace( sentence.charAt(endIndex) ));
}
}
```

After revising your program, there should be no need for comparisons between characters using `==`, `!=`, `>=`, `<=`, `>`, or `<`.

Name your program `Lastname6Extra.java` and submit via email to the grader.

Style counts:

• You should use comments throughout the source code to explain key steps and calculations
• Choose intuitive names for variables
• You should use proper indentation (2-4 spaces) and blank lines to make your program easy to read.
• Do not mix tab and space characters in your indentation—configure your editor to replace tabs with spaces. (Instructions here.)
• Do not exceed 80 characters per line.

Your assignment should be submitted BY EMAIL to our class grader: Andrew Lott, adl316 (AT) nyu (DOT) edu.

• Name your .java file `Lastname6.java`. For example: `Conway6.java`.
• Attach your .java file—and only your .java file—to an email with the subject line "Homework #6".
• Each .java file you submit should begin with a comment of the form:
```/**********************************
* [NAME OF YOUR PROGRAM AND A SHORT DESCRIPTION OF ITS PURPOSE]