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.0.8.47 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.46 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.45 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.44 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.43 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.42 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.41 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.40 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.39 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.38 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.37 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.36 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.35 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.34 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.33 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.32 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.31 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.30 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.29 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java
trackler-2.0.8.28 tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java