import java.util.*; import java.io.*; public class Scrabble { public static void main(String[] args) { Set dictionary = loadDictionary(); List letters = readLetters(); String best = findBestWord(letters, dictionary); System.out.println(best + " (" + scoreWord(best) + ")"); } public static String findBestWord(List letters, Set dict) { } // HELPER METHODS // does not check if word is legal private static int scoreWord(String word) { // A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z 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}; int score = 0; word = word.toUpperCase(); for (int i = 0; i < word.length(); i++) { char ch = word.charAt(i); score += values[ch - 'A']; } return score; } private static List readLetters() { List result = new ArrayList<>(); Scanner input = new Scanner(System.in); System.out.print("Enter letters separated by whitespace: "); Scanner letters = new Scanner(input.nextLine()); while (letters.hasNext()) { String letter = letters.next(); if (letter.length() > 1) { System.out.println(" Skipping " + letter + " - not one letter"); } else { result.add(letter.toUpperCase().charAt(0)); } } return result; } private static Set loadDictionary() { try { Scanner input = new Scanner(new File("dictionary.txt")); Set dict = new HashSet<>(); while (input.hasNextLine()) { dict.add(input.nextLine()); } return dict; } catch (Exception e) { return null; } } }