diff --git a/README.md b/README.md index e57375e..034d920 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/LowercaseSentenceTokenizer.java b/src/LowercaseSentenceTokenizer.java index cc8285d..aabd0ba 100644 --- a/src/LowercaseSentenceTokenizer.java +++ b/src/LowercaseSentenceTokenizer.java @@ -1,3 +1,4 @@ +import java.util.ArrayList; import java.util.List; import java.util.Scanner; @@ -30,7 +31,30 @@ public class LowercaseSentenceTokenizer implements Tokenizer { */ public List tokenize(Scanner scanner) { // TODO: Implement this function to convert the scanner's input to a list of words and periods - return null; + List 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+"); + // 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 != '.'){ + tokens.add(word.toLowerCase()); + } + else{ + String newString = word.substring(0, word.length()-1); + tokens.add(newString); + tokens.add("."); + } + } + } + return tokens; } } diff --git a/src/LowercaseSentenceTokenizerTest.java b/src/LowercaseSentenceTokenizerTest.java index 85ac3a2..b9b3288 100644 --- a/src/LowercaseSentenceTokenizerTest.java +++ b/src/LowercaseSentenceTokenizerTest.java @@ -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 tokens = tokenizer.tokenize(scanner); + + assertEquals(List.of("hello", "hi", "hi", "hi", "hello", "hello"), tokens); + } // Wave 3 @Test