import java.util.*; public class ScrabbleScorer { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Input a valid Scrabble word: "); String word = scan.nextLine(); // assume word is ok for now int score = 0; for (int i = 0; i < word.length(); i++) score += computeValue(word.charAt(i)); System.out.println("WORD: " + word + " WORD SCORE: " + score); } public static int computeValue(char letter) { // Precondition: letter is a valid scrabble letter // (in lowercase) or * for a blank // Returns the scrabble value of the letter or 0 if * String alphabet = "abcdefghijklmnopqrstuvwxyz"; int[] values = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10}; if (letter == '*') return 0; return values[alphabet.indexOf(letter)]; // OR return values[letter-'a']; } }