Players can also use a blank tile (worth 0 points) to substitute for any letter. The score for a word is the sum of the values of the letter tiles.
private static int getLetterScore(char letter)
Try to write your method so you don't test for each letter individually, using an if or switch statement. HINT: Set up an array to hold all of the letter scores, and then use the position of each letter in the alphabet to extract out the corresponding score from the array. If you store the letters of the alphabet in a string, you can use the indexOf method on this string to get the position of any letter of the alphabet.
Since the letter scores and alphabet do not change, you can make these class constants so that it is created just once. That is, after the class header declare and assign an initializer list to your array using the syntax illustrated in the example below.
private static final int[] DATA = {1, 2, 8, 7}; // use all capitals for constantsSimilarly, you can make the alphabet string a class constant.
Test your code to see that it works correctly before moving on.
Sample tests:
WORD WORD SCORE java 14 program 12 equals 15 cla*s 6 banana 8 mississippi 17 zzyzx 42 j*llybea* 19
Also, if the word is 7 or more letters, an additional 50 points is added to the score after all other bonuses are computed.
Modify getWordScore so that it updates the total score for bonuses. You may assume that there is at most one double letter score and one triple letter score. You may also assume there is at most one double or triple word score (but not both). Include a parameter for the method that is Scanner object so that you can continue to get input from the user. Prompt the user as follows:
Is there a DOUBLE LETTER SCORE? [y/n] y Which letter? e Is there a TRIPLE LETTER SCORE? [y/n] n Is there a DOUBLE WORD SCORE? [y/n] yNote that since there is a double word score, the program does not prompt for a triple word score. You may assume for this part that the user input is always valid.
Derive a set of test cases to use that will execute all possible paths through your code that computes bonuses. In a comment in your program, write in the number of different execution paths there are in this part of the program. Test your program thoroughly with the test cases you derived.
Modify your program so that all user input is checked for validity. If any user input is invalid, the user should be prompted to input again until the input is valid. Things to check: