# programming

posted by .

Can anyone help me with this really confusing programming problem?

The board game scrabble works by assigning points to wooden tiles arranged in cells on a board. 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 should include two files: A driver called LineScrabbleDriver, and a file called LineScrabble.java which does the heavy lifting for the application. The LineScrabble file should extend Echo, in the standard way we've indicated (it could also extend the LineReader class).

(Echo Class)
import java.util.Scanner;
import java.io.*;

public class Echo{
String fileName; // external file name
Scanner scan; // Scanner object for reading from external file

public Echo(String f) throws IOException
{
fileName = f;
}

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

public void processLine(String line){ // does the real processing work
System.out.println(line);
}
}

import java.util.Scanner;
import java.io.*;

String fileName; // external file name
Scanner scan; // Scanner object for reading from external file

{
fileName = f;
}
while(scan.hasNext()){
processLine(scan.nextLine());
}
scan.close();
}
public abstract void processLine(String line);
}

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

Tips:

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,… 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 below, sampletext.txt is silly but useful, and HeartOfDarkness.txt is the Conrad novella.

Some sample output:

enter file name

sampletext.txt

winner:

and aid. their. party?

winning score: 40

-------------------------------

enter file name

HeartOfDarkness.txt

winner:

plenty time. i can manage. you take kurtz away quick--quick--i tell

winning score: 192

(HeartOfDarkness.txt)
twiki-edlab(dot)cs(dot)umass(dot)edu/pub/Moll121/AssignSix/HeartOfDarkness.txt
(sample.txt)
twiki-edlab(dot)cs(dot)umass(dot)edu/pub/Moll121/AssignSix/sampletext.txt

• programming -

I got the the LineScrabble class:
import java.io.*;

public class LineScrabble extends Echo{
int max = 0;
String bestLine = "";

public LineScrabble(String f) throws IOException
{
super(f);
}
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};

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];
}
}
System.out.println(score);
}
if(score > max)
{
max = score;
bestLine = s;
}
}

public void results()
{
System.out.println("Winning score: " + max);
System.out.println("Winning line: " + bestLine);
}
}

• programming -

Does anyone have the driver class for this assignment?

## Similar Questions

1. ### physics

A box sits on a horizontal wooden board. The coefficient of static friction between the box and the board is 0.22. You grab one end of the board and lift it up, keeping the other end of the board on the ground. What is the angle between …
2. ### computer programming

Write a program that uses a 20x20 board, initialised to a given pattern, to play the game Conway's life . After each turn print out the board pattern using a . for a dead square and a * for a live square. Squares off the board are …
3. ### computer programming

Write a program that uses a 20x20 board, initialised to a given pattern, to play the game Conway's life . After each turn print out the board pattern using a . for a dead square and a * for a live square. Squares off the board are …
4. ### c programming

Write a program that uses a 20x20 board, initialised to a given pattern, to play the game Conway's life . After each turn print out the board pattern using a . for a dead square and a * for a live square. Squares off the board are …
5. ### c programming

Plz give me some idea that how can i do this program. Write a program that uses a 20x20 board, initialised to a given pattern, to play the game Conway's life . After each turn print out the board pattern using a . for a dead square …
6. ### physics

A bullet is fired through a wooden board with a thickness of 8.0 cm. The bullet hits the board perpendicular to it, and with a speed of +350 m/s. The bullet then emerges on the other side of the board with a speed of +210 m/s. Assuming …
7. ### Physics

A bullet is fired through a wooden board with a thickness of 12.0 cm. The bullet hits the board perpendicular to it, and with a speed of +370 m/s. The bullet then emerges on the other side of the board with a speed of +333 m/s. Assuming …
8. ### physics

A bullet is fired through a wooden board with a thickness of 10.0 cm. The bullet hits the board perpendicular to it, and with a speed of +390 m/s. The bullet then emerges on the other side of the board with a speed of +234 m/s. Assuming …
9. ### MATH HELP

Which of the following questions is a statistical question?
10. ### science

A man of mass 50kg is walking on a long wooden board of mass 200 kg. The wooden board is initially at rest on a frictionless ice surface. If the man walks with a velocity 1m/s in the positive x direction relative to the wooden board,find …

More Similar Questions