add solution for hw6:3233
Some checks failed
Fast Reverse Tests / test (push) Failing after 4s
Reverse Tests / test (push) Failing after 4s
Sum Tests / test (push) Failing after 4s
Word Stat Tests / test (push) Failing after 4s
Word Stat++ Tests / test (push) Failing after 4s

This commit is contained in:
2026-02-02 14:27:24 +03:00
parent ddba0fc8b5
commit d8154da7a9
4 changed files with 64 additions and 25 deletions

View File

@@ -7,6 +7,7 @@ public class WordScanner {
private BufferedReader br;
private String line = null;
private int pos = 0;
private int lineNumber = 0;
public WordScanner(String fileName) throws IOException {
br = new BufferedReader(new InputStreamReader(
@@ -16,14 +17,17 @@ public class WordScanner {
private boolean hasNextLine() throws IOException {
if (line != null && pos < line.length()) return true;
line = br.readLine();
if (line != null) {
lineNumber++;
}
pos = 0;
return line != null;
}
private boolean isWordChar(char c) {
return Character.isLetter(c) || c == '\'' ||
Character.getType(c) == Character.DASH_PUNCTUATION ||
c == '$' || c == '_';
return Character.isLetter(c) || Character.isDigit(c) ||
c == '\'' || c == '$' || c == '_' ||
Character.getType(c) == Character.DASH_PUNCTUATION;
}
public boolean hasNextWord() throws IOException {
@@ -51,7 +55,20 @@ public class WordScanner {
return line.substring(start, pos).toLowerCase();
}
public int getLineNumber() {
return lineNumber;
}
public void close() throws IOException {
br.close();
}
public void reset(String fileName) throws IOException {
br.close();
br = new BufferedReader(new InputStreamReader(
new FileInputStream(fileName), StandardCharsets.UTF_8));
line = null;
pos = 0;
lineNumber = 0;
}
}