From d118c249695223800142c304445735594dd9c3d2 Mon Sep 17 00:00:00 2001 From: kohumukini Date: Thu, 9 Apr 2026 18:14:00 -0700 Subject: [PATCH 1/4] First changes and adjustments --- src/Practice.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index c83a376..f781633 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -17,7 +17,9 @@ public class Practice { * @param items an array of strings to print */ public static void printItems(String[] items) { - // TODO: Implement this method here! + for (String item : items) { + System.out.println(item); + } } /** @@ -44,8 +46,7 @@ public static void printItems(String[] items) { * @return true if a is strictly more than twice the value of b, false otherwise */ public static boolean moreThanDouble(int a, int b) { - // TODO: Delete the dummy return statement and implement this method here! - return false; + return (a % b == 0) && (a / b == 2); } @@ -70,8 +71,15 @@ public static boolean moreThanDouble(int a, int b) { * @return true if every word starts with A (case-insensitive), false otherwise. */ public static boolean allStartWithA(String[] words) { - // TODO: Delete the dummy return statement and implement this method here! - return false; + for (String word : words) + { + word = word.toLowerCase() + if (!word.startsWith("a")) { + return false; + } + } + + return true; } public static void main(String[] args) { From 544e756067ef31a0acaf46165b1326c8b6c05879 Mon Sep 17 00:00:00 2001 From: kohumukini Date: Thu, 9 Apr 2026 18:16:21 -0700 Subject: [PATCH 2/4] Fixed syntax error(s) --- src/Practice.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index f781633..f8e730a 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -73,7 +73,7 @@ public static boolean moreThanDouble(int a, int b) { public static boolean allStartWithA(String[] words) { for (String word : words) { - word = word.toLowerCase() + word = word.toLowerCase(); if (!word.startsWith("a")) { return false; } From 1e844485976c61e9c04e1ce4abe9ca8741e49883 Mon Sep 17 00:00:00 2001 From: kohumukini Date: Thu, 9 Apr 2026 18:25:17 -0700 Subject: [PATCH 3/4] Added new test cases --- src/Practice.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Practice.java b/src/Practice.java index f8e730a..782371d 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -46,7 +46,7 @@ public static void printItems(String[] items) { * @return true if a is strictly more than twice the value of b, false otherwise */ public static boolean moreThanDouble(int a, int b) { - return (a % b == 0) && (a / b == 2); + return a / b >= 2 && a / b % 2 != 0; } @@ -103,5 +103,18 @@ public static void main(String[] args) { System.out.println("allStartWithA(new String[]{\"apes\", \"can\", \"be\", \"amazing\"}): " + allStartWithA(new String[]{"apes", "can", "be", "amazing"})); System.out.println("allStartWithA(new String[]{}): " + allStartWithA(new String[]{})); System.out.println(); + + System.out.println("Calling printItems with String[]{{\"Hi\", \"There\\n\", \"maybe\", \"we\", \"if23 asd\"}"); + printItems(new String[]{"Hi", "There\n", "maybe", "we", "if23 asd"}); + System.out.println(); + + System.out.println("Calling moreThanDouble with values (3,2), (100,10), (60/29)"); + System.out.println("moreThanDouble(3,2)" + moreThanDouble(3,2)); + System.out.println("moreThanDouble(100,10)" + moreThanDouble(100,10)); + System.out.println("moreThanDouble(60,29)" + moreThanDouble(60,29)); + System.out.println(); + + System.out.println(); + System.out.println("allStartsWithA(new String[]{\" a\", \"almost\", \"anything\", \"\\nanyways\"});" + allStartWithA(new String[]{" a", "almost", "anything", "\nanyways"})); } } From 1d2b64316bdbdcc4852d2bd84962fea584f0f062 Mon Sep 17 00:00:00 2001 From: kohumukini Date: Thu, 9 Apr 2026 18:31:49 -0700 Subject: [PATCH 4/4] Added new edge cases & improved functions --- src/Practice.java | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index 782371d..6a1a925 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -46,7 +46,11 @@ public static void printItems(String[] items) { * @return true if a is strictly more than twice the value of b, false otherwise */ public static boolean moreThanDouble(int a, int b) { - return a / b >= 2 && a / b % 2 != 0; + if (b == 0) { + System.out.println(" --Undefined-- "); + return false; + } + return (double) a / b > 2; } @@ -73,7 +77,7 @@ public static boolean moreThanDouble(int a, int b) { public static boolean allStartWithA(String[] words) { for (String word : words) { - word = word.toLowerCase(); + word = word.strip().toLowerCase(); if (!word.startsWith("a")) { return false; } @@ -108,13 +112,16 @@ public static void main(String[] args) { printItems(new String[]{"Hi", "There\n", "maybe", "we", "if23 asd"}); System.out.println(); - System.out.println("Calling moreThanDouble with values (3,2), (100,10), (60/29)"); - System.out.println("moreThanDouble(3,2)" + moreThanDouble(3,2)); - System.out.println("moreThanDouble(100,10)" + moreThanDouble(100,10)); - System.out.println("moreThanDouble(60,29)" + moreThanDouble(60,29)); + System.out.println("Calling moreThanDouble with values (3,2), (100,10), (60,29), (1,0), (0,1)"); + System.out.println("moreThanDouble(3,2): " + moreThanDouble(3,2)); + System.out.println("moreThanDouble(100,10): " + moreThanDouble(100,10)); + System.out.println("moreThanDouble(60,29): " + moreThanDouble(60,29)); + System.out.println("moreThanDouble(0,1): " + moreThanDouble(0,1)); + System.out.println(); + System.out.println("moreThanDouble(1,0): " + moreThanDouble(1,0)); System.out.println(); System.out.println(); - System.out.println("allStartsWithA(new String[]{\" a\", \"almost\", \"anything\", \"\\nanyways\"});" + allStartWithA(new String[]{" a", "almost", "anything", "\nanyways"})); + System.out.println("allStartsWithA(new String[]{\" a\", \"almost\", \"anything\", \"\\nanyways\"}): " + allStartWithA(new String[]{" a", "almost", "anything", "\nanyways"})); } }