From 1d29aa64c73eb9ef7b6cd3a276f74594061386e8 Mon Sep 17 00:00:00 2001 From: konradkelly Date: Mon, 7 Apr 2025 23:56:38 -0700 Subject: [PATCH 1/3] ADDED STATIC METHODS TO PRINT STRING ARRAYS --- src/Practice.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index 89acfd9..4a645b5 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -14,10 +14,16 @@ public class Practice { * sdev * 220 * + * + * * @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); + } } /** @@ -82,6 +88,10 @@ public static void main(String[] args) { System.out.println(); System.out.println("Calling printItems(new String[]{\"hello\", \"world\"})"); printItems(new String[]{"hello", "world"}); + } +} +/* + System.out.println(); System.out.println("///// More than Double /////"); @@ -95,5 +105,5 @@ 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(); - } -} \ No newline at end of file + */ + From bbb5e0076735c020f94286b7492fb854d42c8ec1 Mon Sep 17 00:00:00 2001 From: konradkelly Date: Tue, 8 Apr 2025 11:11:13 -0700 Subject: [PATCH 2/3] ADDED LOGIC TO BOOLEAN METHOD --- src/Practice.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index 4a645b5..38472cb 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -50,7 +50,9 @@ 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! + if (a > b * 2) { + return true; + } return false; } @@ -88,16 +90,17 @@ public static void main(String[] args) { System.out.println(); System.out.println("Calling printItems(new String[]{\"hello\", \"world\"})"); printItems(new String[]{"hello", "world"}); - } -} -/* - - System.out.println(); System.out.println("///// More than Double /////"); System.out.println("moreThanDouble(10, 3): " + moreThanDouble(10, 3)); System.out.println("moreThanDouble(6, 4): " + moreThanDouble(6, 4)); System.out.println("moreThanDouble(4, 2): " + moreThanDouble(4, 2)); + } +} +/* + + + System.out.println(); System.out.println("///// All Start With A /////"); From 8ee43f25fca9b5dc3d77e03b0bd7e9e1b8a26625 Mon Sep 17 00:00:00 2001 From: konradkelly Date: Tue, 8 Apr 2025 11:54:53 -0700 Subject: [PATCH 3/3] ADDED BOOLEAN METHOD FOR WORDS STARTING WITH THE LETTER 'A' (CASE-INSENSITIVE) --- src/Practice.java | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Practice.java b/src/Practice.java index 38472cb..50d8379 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -78,8 +78,17 @@ 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; + if (words == null || words.length == 0) { + return true; + } + + for (String word : words) { + if (!word.toLowerCase().startsWith("a")) { + return false; + } + } + + return true; } public static void main(String[] args) { @@ -95,6 +104,12 @@ public static void main(String[] args) { System.out.println("moreThanDouble(10, 3): " + moreThanDouble(10, 3)); System.out.println("moreThanDouble(6, 4): " + moreThanDouble(6, 4)); System.out.println("moreThanDouble(4, 2): " + moreThanDouble(4, 2)); + System.out.println(); + System.out.println("///// All Start With A /////"); + System.out.println("allStartWithA(new String[]{\"alligators\", \"are\", \"AWESOME\"}): " + allStartWithA(new String[]{"alligators", "are", "AWESOME"})); + 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(); } } /* @@ -102,11 +117,6 @@ public static void main(String[] args) { - System.out.println(); - System.out.println("///// All Start With A /////"); - System.out.println("allStartWithA(new String[]{\"alligators\", \"are\", \"AWESOME\"}): " + allStartWithA(new String[]{"alligators", "are", "AWESOME"})); - 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(); + */