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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This is a large, difficult project. Start early, and get help when you need it.
code .
```
If the above command does not work, you can open VS Code manually and select the ramblebot folder to open.
Make sure you modify the read me and push the change on your own fork!
1. Open `RambleApp.java`. Click anywhere in the text of the file
1. Scroll to the bottom to find the `main` method. There should be a small grey "run" button above it. Click "Run".
![Run Button in VS Code](images/run_button.png)
Expand Down
26 changes: 25 additions & 1 deletion 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 @@ -30,7 +31,30 @@ public class LowercaseSentenceTokenizer implements Tokenizer {
*/
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;
List<String> tokens = new ArrayList<>();
// reads whole scanner
while(scanner.hasNextLine()) {
// stores the line
String line = scanner.nextLine();
// makes an array from the line using spaces gets rid of extra spaces with +
// source for \\s vs \\s+ : https://stackoverflow.com/a/15625711
String[] list = line.split("\\s+");
Comment on lines +38 to +41
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for citing your source! You can also rely on scanner.next which handles the whitespace for you automatically

// adds items in array to the list of tokens
for(int i = 0; i < list.length; i++) {
String word = list[i];
//only way I know how to solve the last two test cases
char last = word.charAt(word.length()-1);
if(last != '.'){
Comment on lines +46 to +47
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works well! You can also use endsWith here

tokens.add(word.toLowerCase());
}
else{
String newString = word.substring(0, word.length()-1);
tokens.add(newString);
tokens.add(".");
}
}
}
return tokens;
}
}

9 changes: 8 additions & 1 deletion src/LowercaseSentenceTokenizerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ void testTokenizeWithNoCapitalizationOrPeriod() {
/*
* Write your test here!
*/

@Test
void testTokenizeWithMultipleSpaces() {
LowercaseSentenceTokenizer tokenizer = new LowercaseSentenceTokenizer();
Scanner scanner = new Scanner("hello hi hi hi hello hello");
List<String> tokens = tokenizer.tokenize(scanner);

assertEquals(List.of("hello", "hi", "hi", "hi", "hello", "hello"), tokens);
}
Comment on lines +22 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
@Test
Expand Down