Sha256: 66d7a8916e90ecdc67a156e96c1c4080ff1215dfd195a2b4d838bd69b021e662

Contents?: true

Size: 1.52 KB

Versions: 167

Compression:

Stored size: 1.52 KB

Contents

import java.util.Map;
import java.util.HashMap;

public class Scrabble {

    private String word;

    private static final Map<Character, Integer> letterScores = new HashMap<>();

    static {
        letterScores.put('a', 1);
        letterScores.put('e', 1);
        letterScores.put('i', 1);
        letterScores.put('o', 1);
        letterScores.put('u', 1);
        letterScores.put('l', 1);
        letterScores.put('n', 1);
        letterScores.put('r', 1);
        letterScores.put('s', 1);
        letterScores.put('t', 1);
        letterScores.put('d', 2);
        letterScores.put('g', 2);
        letterScores.put('b', 3);
        letterScores.put('c', 3);
        letterScores.put('m', 3);
        letterScores.put('p', 3);
        letterScores.put('f', 4);
        letterScores.put('h', 4);
        letterScores.put('v', 4);
        letterScores.put('w', 4);
        letterScores.put('y', 4);
        letterScores.put('k', 5);
        letterScores.put('j', 8);
        letterScores.put('x', 8);
        letterScores.put('q', 10);
        letterScores.put('z', 10);
    }

    private Object score;

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

    public int getScore() {
        return getScore(word);
    }

    public static int getScore(String input) {
        if (input == null || input.trim().isEmpty()) {
            return 0;
        }

        int score = 0;

        for (char letter : input.toLowerCase().toCharArray()) {
            score += letterScores.get(letter);
        }

        return score;
    }
}

Version data entries

167 entries across 167 versions & 1 rubygems

Version Path
trackler-2.1.0.11 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.1.0.10 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.1.0.9 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.1.0.8 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.1.0.7 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.1.0.6 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.1.0.5 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.1.0.4 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.1.0.3 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.1.0.2 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.1.0.1 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.1.0.0 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.55 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.54 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.53 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.52 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.51 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.50 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.49 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.48 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java