From 9c261da4a450d7f092d1343813c26f12322a78ef Mon Sep 17 00:00:00 2001 From: Gabby-Moon <194023457+Gabby-Moon@users.noreply.github.com> Date: Tue, 21 Jan 2025 11:47:47 -0800 Subject: [PATCH 1/4] modified read me file --- README.md | 1 + 1 file changed, 1 insertion(+) 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) From 8f3b17b74b3171dd7129170fcccaba42128efc6e Mon Sep 17 00:00:00 2001 From: Gabby-Moon <194023457+Gabby-Moon@users.noreply.github.com> Date: Wed, 29 Jan 2025 11:04:35 -0800 Subject: [PATCH 2/4] Finished wave 1 --- src/LowercaseSentenceTokenizer.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/LowercaseSentenceTokenizer.java b/src/LowercaseSentenceTokenizer.java index cc8285d..8cde2e7 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,19 @@ 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 + String[] list = line.split("\\s"); + // adds items in array to the list of tokens + for(int i = 0; i < list.length; i++) { + tokens.add(list[i]); + } + } + return tokens; } } From 0a8bfd317e09518603095e9d44cb121474dddd3a Mon Sep 17 00:00:00 2001 From: Gabby-Moon <194023457+Gabby-Moon@users.noreply.github.com> Date: Wed, 29 Jan 2025 12:27:40 -0800 Subject: [PATCH 3/4] Finished wave 2 --- src/LowercaseSentenceTokenizer.java | 5 +++-- src/LowercaseSentenceTokenizerTest.java | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/LowercaseSentenceTokenizer.java b/src/LowercaseSentenceTokenizer.java index 8cde2e7..052ee6e 100644 --- a/src/LowercaseSentenceTokenizer.java +++ b/src/LowercaseSentenceTokenizer.java @@ -36,8 +36,9 @@ public List tokenize(Scanner scanner) { while(scanner.hasNextLine()) { // stores the line String line = scanner.nextLine(); - // makes an array from the line - String[] list = line.split("\\s"); + // 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++) { tokens.add(list[i]); 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 From 9696c11c5284a013fc5ed46cf7778922d9b3d86b Mon Sep 17 00:00:00 2001 From: Gabby-Moon <194023457+Gabby-Moon@users.noreply.github.com> Date: Wed, 29 Jan 2025 16:43:57 -0800 Subject: [PATCH 4/4] Finished wave 3 --- src/LowercaseSentenceTokenizer.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/LowercaseSentenceTokenizer.java b/src/LowercaseSentenceTokenizer.java index 052ee6e..aabd0ba 100644 --- a/src/LowercaseSentenceTokenizer.java +++ b/src/LowercaseSentenceTokenizer.java @@ -41,7 +41,17 @@ public List tokenize(Scanner scanner) { String[] list = line.split("\\s+"); // adds items in array to the list of tokens for(int i = 0; i < list.length; i++) { - tokens.add(list[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;