When I try to compile this, it keeps saying that there is an illegal start of ex
ID: 3647118 • Letter: W
Question
When I try to compile this, it keeps saying that there is an illegal start of expression at the bottom - on the line "public void result() { ". Can anyone help me fix this?import java.io.*;
import java.util.*;
public class LineScrabble extends Echo{
int sum = 0;
int score = 0;
String winnerLine = " ";
public LineScrabble(String f) throws IOException
{
super(f);
}
int[] a = new int[]{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 line){
String line1 = line.toLowerCase();
int value;
for (int j = 0; j < line1.length(); j++){
value = line1.charAt(j) - 'a';
if(value >= 0 && value < 26)
sum = sum + letter(value);
}
if (sum > score){
sum = score;
line = winnerLine;
}
public void result(){
System.out.println("winner" + winnerLine);
System.out.println("Score" + score);
}
}
}
Here's the echo class, should you need it -
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;
scan = new Scanner(new FileReader(fileName));
}
public void readLines(){ // reads lines, hands each to processLine
while(scan.hasNext()){
processLine(scan.nextLine());
}
scan.close();
}
public void processLine(String line){ // does the real processing work
System.out.println(line);
}
}
Explanation / Answer
Errors:- import java.io.*; import java.util.*; Correct ones:- import java.io*; import java.util.Scanner*; Remaining code is correct and working also
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.