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: 3627664 • 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.
We'll simplify this considerably, and consider the following question. We begin with the letter-scoring scheme from Scrabble:
a = 1, b = 3, c = 3, d = 2, ..., z = 10.
Given a text file - a novel for example, what is the highest-(or a highest-) scoring line in the the file? In keeping with the Scrabble style, we'll add double and triple letter scores: any letter that falls at a line (String) position that's evenly divisible by 4 will have its score doubled; and any letter that falls at a line (String) position that's evenly divisible by 9 will have its score tripled. A letter at a position that's evenly divisible by 4 and 9 will have its score doubled, not tripled. All non-letters (e.g., space, comma, etc.) have score 0.

Example: the line "now is the time" has a Scrabble score (by our rules) of 29. (Verify this with pencil and paper. Note that "n" is at position 0, which is a double letter score.)

Your solution is in two classes: A driver class called LineScrabbleDriver, and a class called LineScrabble, which does the heavy lifting for the application. The LineScrabble class should extend Echo, in the standard way we've indicated (it could also extend the LineReader class from Chapter 11 of the text). Submit the code to these classes in the boxes below.

Output: your program should report the (or a) highest scoring line in the input file, along with the score for that line.

Tips:

Make sure you master Chapter 10 of the text as a prelude to doing this problem.

Here is a list from a to z of the letter scores from Scrabble:

{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}

Notice that this list is in proper format for copying and pasting directly into your program as an int array.

It's far easier to convert lines of text to lowercase before processing.

You MUST use a try-catch harness in driver class.

You MUST comment every method with a one line description of the job that method does, and your description must be placed just below the method header line.

Two sample files are provided: sampletext.txt is silly but useful, and HeartOfDarkness.txt is the famous novella by Joseph Conrad.

Some sample output:
enter file name
sampletext.txt
winner: "and aid. their. party?" score: 40
-------------------------------
enter file name
HeartOfDarkness.txt
winner: "plenty time. i can manage. you take kurtz away quick--quick--i tell" score: 192

my code:
//LineScrabbleDriver.java
import java.util.Scanner;
import java.io.*;
public class LineScrabbleDriver {
public static void main(String args[]) throws IOException {
System.out.println("Enter file name: ");
Scanner scan=new Scanner(System.in);
//gets the filename from the user
String fileName=scan.nextLine();
//creats an object for LineScrable class and passes the
//filename as parameter
LineScrabble ls=new LineScrabble(fileName) ;
//reads each line from the file
//and process it
ls.readLines();
//displays the winner
ls.results();
}
}

//LineScrabble.java
import java.io.*;
public class LineScrabble extends Echo{
int max = 0;
String bestLine = "";
public LineScrabble(String f) throws IOException {
super(f);
}
//scrabbles
int[] scrabbles = {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};
//process the given line
public void processLine(String s) {
s.toLowerCase();
int score = 0;
for(int i = 0; i<s.length(); i++){
int w = (int)(s.charAt(i)-97);
if (w >=0 && w <= 25) {
if (i == 0) {
score += 2*scrabbles[w];
} else if (i%4==0 && i%9==0) {
score += 2*scrabbles[w];
} else if (i%9==0) {
score += 3*scrabbles[w];
} else if (i%4==0) {
score += 2*scrabbles[w];
}
}
}
if(score > max) {
max = score;
bestLine = s;
}
}
//displays the winner and score
public void results() {
System.out.println("Winner: " + bestLine);
System.out.println("score: " + max);
}
}

but I get an error when I try to test the program:
java.io.FileNotFoundException: now is the time (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at java.io.FileReader.<init>(FileReader.java:41)
at Echo.<init>(Echo.java:8)
at LineScrabble.<init>(LineScrabble.java:6)
at LineScrabbleDriver.main(LineScrabbleDriver.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:271)
>



WHAT AM I DOING WRONG??

Explanation / Answer

import java.util.*; import java.io.*; public class ScrabbleDriver{ public static void main(String args[]) { try{ Scanner s = new Scanner(System.in); System.out.println("enter file name, then word size"); String f = s.next(); int size = s.nextInt(); Scrabble scrab = new Scrabble(f,size); scrab.readLines(); scrab.reportWinner(); } catch(Exception e) {System.out.println(e);} } }

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