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

The board game Scrabble works by assigning points to wooden tiles arranged in ce

ID: 3581417 • Letter: T

Question

The board game Scrabble works by assigning points to wooden tiles arranged in cells on a board. It's described here: Scrabble on Wikipedia.


For this project, you will write code that computes the Scrabble score for each line of text in a file and reports the line with the maximal Scrabble score and that score.

Computing the Scrabble Score


The Scrabble score for a line of text is the sum of the scores for all of the individual characters in that line. The Scrabble score for a single character is computed as follows:
For each character in the line:

If the character is a letter, get the letter score. If it is not a letter, its score is zero. The case of the letter (upper/lower case) does not matter.

If the position of the character (position is its index- the first character is position 0) is divisible by 4, the score is doubled.

If the position of the character is divisible by 9, the score is tripled.

If the position of the character is divisible by 4 and 9, the score is doubled.

Required Code Structure


This project utilizes three source files: A driver class called ScrabbleDriver, a class that opens the file and uses a Scanner to access the lines of text called TextFileAccessor, and the MaxScrabbleScore class- which you will write for this project. The MaxScrabbleScore class must extend the TextFileAccessor class. The starter files can be downloaded here:
MaxScrabbleStarterFiles.zip

import java.util.Scanner;
import java.io.IOException;

public class ScrabbleDriver{
public static void main(String args[])
{
try{
Scanner s = new Scanner(System.in);
System.out.println("Enter the file name:");
String fileName = s.nextLine();
TextFileAccessor scrab = new MaxScrabbleScore();
scrab.openFile(fileName);
scrab.processFile();
System.out.println(scrab.getReportStr());
}
catch(IOException ioex)
{System.out.println(ioex);}
}
}

import java.util.Scanner;
import java.io.IOException;
import java.io.FileReader;


public abstract class TextFileAccessor {
   protected String fileName;
   protected Scanner scan;

// throws a FileNotFoundException if can't open file
public void openFile(String fn)throws IOException {
    fileName = fn;
       scan = new Scanner(new FileReader(fileName));
}

   public void processFile() {
       while (scan.hasNext()) {
           processLine(scan.nextLine());
       }
       scan.close();
   }

   protected abstract void processLine(String line);

public abstract String getReportStr();

}

Testing Your Code

Further Requirements

Your MaxScrabbleScore class must properly extend the TextFileAccessor class. There must not be any unnecessary duplication of superclass code in MaxScrabbleScore.

Your MaxScrabbleScore class must compile and run with the other two source files provided with this project. You may not modify these files.

Your MaxScrabbleScore class must produce the output in the same format as shown in the above section Testing Your Code. Points off if your values are correct but you don't match the output as shown above.

Your code for the MaxScrabbleScore class must use an int array to store the letter scores given in the table above. This array must be used to compute the individual letter scores in the lines of text.

Your code for the MaxScrabbleScore class may not import any Java libraries.



Enter your MaxScrabbleScore class definition in the box below.

Letter ABC DE FG H I J KLM N O P Q R S T U V W X Y Z Score 1 31 3 21 1 4 24 18 51 3 1 1 3 10 1 1 1 1 4 4 5 4 10

Explanation / Answer

PROGRAM CODE:

package scrabble;

public class MaxScrabbleScore extends TextFileAccessor{
   private int scores[] = {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};
     
   private String report;
  
   public MaxScrabbleScore() {
       report = "My scrabble score: ";
   }
   @Override
   protected void processLine(String line) {
           int score = 0;
       for(int i =0; i<line.length(); i++)
       {
           char letter = line.charAt(i);
           if(Character.isLetter(letter))
           {
               letter = Character.toLowerCase(letter);
               int letterValueInt = scores[Character.getNumericValue(letter) - 10];
               if(i % 4 == 0 && i % 9 == 0)
                   letterValueInt = letterValueInt * 2;
               else if(i % 4 == 0)
                   letterValueInt = letterValueInt * 2;
               else if(i % 9 == 0)
                   letterValueInt = letterValueInt * 3;
              
               score += letterValueInt;
           }
       }
      
report += score + " for this line:" + " " + line;
      
   }

   @Override
   public String getReportStr() {
      
       return report;
   }

}

OUTPUT:

Enter the file name:
input.txt
My scrabble score: 40 for this line: and aid. their. party?

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote