Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java word game In most word games, each letter in a word is scored according to

ID: 3671744 • Letter: J

Question

java word game

In most word games, each letter in a word is scored according to its point value, which is inversely proportional to its frequency in English words. In Scrabble, the points and letter distribution are allocated as shown in the table. Write a Java program that reads in a word (not a sentence) and prints out the score in Scrabble, not counting any other bonuses that occur in the game. Make sure the program handles blank tiles. Represent a blank tile with a #. For example, the Scrabble word "FARM"is worth 9 points: 4 for the F, 1 each for the A and the R, and 3 for the M. However, the word SYZYGY-should be worth: 1 + 4 +10+ 4 + 2 + 0 = 21 points since Y is only found twice a blank tile must be used. Check for the proper number of tiles- assume a maximum of seven letters on a rack as well as ignore any characters other than uppercase letters in computing the score. Output should look similar to below. Sample Run: Enter a word: SYZYGY English-language editions of Scrabble contain 100 letter tiles, in the following distribution: 2 blank tiles E x12, A x9,1 x9, O x8, N x6, R x6. T x6, L x4, S x4, U x4 2 points: D x4. G x3 3 points: B x2, C x2, M x2, P x2 4 points: F x2, H x2. V x2, W x2. Y x2 5 points: K x1 8 points: J x1. X x1 10 points: Q x1,Z xl 1 Word: SYZYG# Scrabble score is: 1+4+ 10 +4+2+0= 21 Name the program: ModifiedScrabbleScoreXX. java, where XX are your initials.

Explanation / Answer

import acm.program.*;
public class ScrabbleCalc extendsProgram
{
public void run()
{
String word = readLine("Enter Scrabble word (all in uppercase) and we'll calculate your score: ");
print(scrabbleScore(word));
}
private int scrabbleScore(String scrabbleWord)
{
int score = 0;
for (int i = 0; i < scrabbleWord.length(); i++)
{
char calculatedLetter = scrabbleWord.charAt(i);
switch (calculatedLetter)
{
case 'A':
case 'E':
case 'I':
case 'L':
case 'N':
case 'O':
case 'R':
case 'S':
case 'T':
case 'U':
score +=1;
break;
case 'D':
case 'G':
score +=2;
break;
case 'B':
case 'C':
case 'M':
case 'P':
score +=3;
break;
case 'F':
case 'H':
case 'V':
case 'W':
case 'Y':
score +=4;
break;
case 'K':
score +=5;
break;
case 'J':
case 'X':
score +=8;
break;
case 'Q':
case 'Z':
score +=10;
break;
default:
break;
}
}
return score;
}
}