Untitled

                Never    
Java
       
class Scrabble {

    private String word;
    //                                   a, b, c, d, e, f, g, h, i, j, k, l, m,
    private static final int[] points = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3,
      // n, o, p, q,  r, s, t, u, v, w, x, y, z
         1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10};

    Scrabble(String word) {
        this.word = word;
    }

    int getScore() {
        int score = 0;
        if (word.length() == 0) return score;
        for (int i = 0; i < word.length(); i++) {
            score += points[Character.toLowerCase(word.charAt(i)) - 'a'];
        }
        return score;
    }

    /* For extensions, also pass in array of the board spaces the word uses
    *  empty square - '0'
    * double word score - '1'
    * triple word score - '2'
    * double letter score - '3'
    * triple letter score - '4'
    * If I was implementing a full game of scrabble I would use a 2d array
    * of the board and pass in word position info but this will be fine to
    * demonstrate how it works
    */
    int getScoreWithBoard(char[] board) {
        int score = 0;
        int wordMultiplier = 1;
        if (word.length() == 0) return score;
        for (int i = 0; i < word.length(); i++) {
            int s = points[Character.toLowerCase(word.charAt(i)) - 'a'];
            // Could have used a switch statement here instead
            if (board[i] == '1') {
                wordMultiplier *= 2;
            } else if (board[i] == '2') {
                wordMultiplier *= 3;
            } else if (board[i] == '3') {
                s *= 2;
            } else if (board[i] == '4') {
                s *= 3;
            }
            score += s;
        }
        return score * wordMultiplier;
    }

}

Raw Text