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:

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:


Extra Credit (5 points):

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

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:

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

Last modified: 21 Jun 2009