Created
June 20, 2013 07:35
-
-
Save mankyKitty/5820886 to your computer and use it in GitHub Desktop.
It's been a while okay!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scrabble; | |
public class Scrabble { | |
private static final char[][] letters = new char[][] { | |
{'a','e','i','o','u','l','n','r','s','t'}, // 1 | |
{'d','g'}, // 2 | |
{'b','c','m','p'}, // 3 | |
{'f','h','v','w','y'}, // 4 | |
{'k'}, // 5 | |
{'j','x'}, // 8 | |
{'q','z'} // 10 | |
}; | |
private static int getWordScore(String word) { | |
int finalScore = 0; | |
char[] list = word.toCharArray(); | |
for (int i = 0; i < list.length; i++) { | |
finalScore = finalScore + getLetterScore(list[i]); | |
} | |
return finalScore; | |
} | |
private static int getLetterScore(char letter) { | |
int score = 0; | |
for (int i = 0; i < letters.length; ++i) { | |
for (int j = 0; j < letters[i].length; j++) { | |
if (letter == letters[i][j]) { | |
// We've found our letter! | |
score = i; | |
break; | |
} | |
} | |
if (score > 0) { | |
// Make sure we don't keep searching! | |
break; | |
} | |
} | |
if (score == 6) { | |
return 8; | |
} | |
else if (score == 7) { | |
return 10; | |
} | |
else { | |
return (score + 1); | |
} | |
} | |
public static void main(String[] args) { | |
System.out.println(getWordScore("cabbage")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment