The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 4 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Java Programming Project: Max Scrabble ScoreOverview
Â
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.
Learning Objectives
Â
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:
Â
This table lists the Scrabble letter scores:
A-1
B-3
C-3
D-2
E-1
F-4
G-2
H-4
I-1
J-8
K-5
L-1
M-3
N-1
O-1
P-3
Q-10
R-1
S-1
T-1
U-1
V-4
W-4
X-8
Y-4
Z-10
Â
For example, given this line of text:
Dave, I am afraid.
The Scrabble score for that line would be: 38
Note that the first position of the input string is zero, which is divisible by 4 and 9, so the character score for the first letter, D, which is 2, is doubled.
Â
Another example: this line:
now is the timeÂ
has a Scrabble score of 29.
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.
Â
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();
Â
}
Â
------------------------------------------------------------------------------------------------
Â
public class MaxScrabbleScore extends TextFileAccessor {
 //declare variables
public MaxScrabbleScore(){
 //initialise variables in constructor
}
protected void processLine(String curLine) {
 // process each character from the current line
 //calculate sum of the scores for characters in that line
}
private int getScrabbleScore(char c, int pos){
 //helper method to return the score for the character
}
public String getReportStr(){
 //returns the score and the string that was entered
}
Â
}//end class
Â
Â
Testing Your Code
Strongly Suggested:
Â
Â
Â
PROJECT REQUIREMENTS
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly