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.
In your solution, you should include a method that returns the Scrabble point value of a given character. If the character is not a letter, return 0. 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 as we did in lecture, you can use the indexOf method on this string to get the position of any letter of the alphabet.
To initialize an array directly, you can use the syntax illustrated in the example below:
int[] data = {1, 3, 2, 7, 4};To access the array, simply use the array name and a subscript in square brackets. For example, the following code adds up the integers in the data array declared above:
int sum = 0; for (int i = 0; i < data.length; i++) sum += data[i];
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 your program 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). 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: