diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..b3c2339 Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index e57375e..60d3f9b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/LowercaseSentenceTokenizer.java b/src/LowercaseSentenceTokenizer.java index cc8285d..87c26a6 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; @@ -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 tokenize(Scanner scanner) { - // TODO: Implement this function to convert the scanner's input to a list of words and periods - return null; + + public List tokenize(Scanner scanner) { + List 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); } } +return tokens; + } + } diff --git a/src/LowercaseSentenceTokenizerTest.java b/src/LowercaseSentenceTokenizerTest.java index 85ac3a2..701e90f 100644 --- a/src/LowercaseSentenceTokenizerTest.java +++ b/src/LowercaseSentenceTokenizerTest.java @@ -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 tokens = tokenizer.tokenize(scanner); + List expected = List.of("hello", "hi", "hi", "hi", "hello", "hello"); + + assertEquals(expected, tokens, "Tokens did not match "); +} + // Wave 3