Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ A project to exercise Java, JUnit, git, GitHub, and code-reading skills. Student
## Expectations

### Academic Honesty

test change
another test change
THIS IS AN INDIVIDUAL PROJECT. The following is not allowed:
- You MAY NOT copy any code from an AI.
- You MAY NOT paste any of the project or your code into an AI.
Expand Down
24 changes: 21 additions & 3 deletions src/LowercaseSentenceTokenizer.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

Expand Down Expand Up @@ -28,9 +29,26 @@ public class LowercaseSentenceTokenizer implements Tokenizer {
* @param scanner the Scanner to read the input text from
* @return a list of tokens, where each token is a word or a period
*/
public List<String> tokenize(Scanner scanner) {
// TODO: Implement this function to convert the scanner's input to a list of words and periods
return null;

public List<String> tokenize(Scanner scanner) {
List<String> tokens = new ArrayList<>();

while (scanner.hasNext()) {
String token = scanner.next().toLowerCase();
if (token.endsWith(".")) {
if (token.length() == 1) {
tokens.add(".");

}else {
String wordWithoutPeriod = token.substring(0, token.length() - 1);
tokens.add(wordWithoutPeriod);
tokens.add(".");
}
} else {
tokens.add(token);
Comment on lines +33 to +48
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great logic!

}
}
return tokens;
}
}

17 changes: 13 additions & 4 deletions src/LowercaseSentenceTokenizerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ void testTokenizeWithNoCapitalizationOrPeriod() {
assertEquals(List.of("this", "is", "a", "lowercase", "sentence", "without", "a", "period"), tokens);
}

// Wave 2
/*
* Write your test here!
*/
// Wave 2
@Test
void testTokenizeWithManySpaces() {
LowercaseSentenceTokenizer tokenizer = new LowercaseSentenceTokenizer();
String input = "hello hi hi hi hello hello";
Scanner scanner = new Scanner(input);

List<String> tokens = tokenizer.tokenize(scanner);
List<String> expected = List.of("hello", "hi", "hi", "hi", "hello", "hello");

assertEquals(expected, tokens, "Tokens did not match ");
}
Comment on lines +19 to +29
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test!




// Wave 3
Expand Down