diff --git a/README.md b/README.md index 64cab1e..c26c1eb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Practice writing Java code and using git/GitHub. Complete the github-intro assignment before this one! ## Setup -Fork and clone this repository. Do not forget to fork before cloning! For a refresher on git/GitHub, see the instructions on the github-intro repository. You will not need to create a `sdev220` directory again, you can re-use the exisiting one you have already made. +Fork and clone this repository. Do not forget to fork before cloning! For a refresher on git/GitHub, see the instructions on the github-intro repository. You will not need to create a `cs123` directory again, you can re-use the exisiting one you have already made. ## **Commit Frequently!** To receive full credit **you MUST commit frequently** for this assignment. At the very least, make one commit after completing each method. Make sure to push after each commit! @@ -23,11 +23,11 @@ This will compile your code and run the main method of the Practice class. Befor ///// Print items ///// -Calling printItems(new String[]{"welcome", "to", "sdev", "220"}) +Calling printItems(new String[]{"welcome", "to", "cs", "123"}) welcome to -sdev -220 +cs +123 Calling printItems(new String[]{"hello", "world"}) hello diff --git a/src/Practice.java b/src/Practice.java index 89acfd9..81d0d05 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -6,18 +6,22 @@ public class Practice { * Example: * * input: - * {"welcome", "to", "sdev", "220"} + * {"welcome", "to", "cs", "123"} * * printed output: * welcome * to - * sdev - * 220 + * cs + * 123 * * @param items an array of strings to print */ + public static void printItems(String[] items) { - // TODO: Implement this method here! + // goes down the items array and prints each item + for (String item : items) { + System.out.println(item); + } } /** @@ -44,8 +48,12 @@ 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; + int result = a - b; + if (result > b) { + return true; + } else { + return false; + } } @@ -70,15 +78,28 @@ 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; - } + //check if array is empty + if (words.length <= 0 || words == null) { + return true; + } + char aCheck[] = {'a', 'A'}; + boolean verified = false; + for (String word : words) { + char first = word.charAt(0); //https://www.w3schools.com/java/ref_string_charat.asp + if (first == aCheck[0] || first == aCheck[1]) { + verified = true; + } else { + return false; + } + } + return verified; //for each loop should adjust verified + } public static void main(String[] args) { System.out.println(); System.out.println("///// Print items /////"); - System.out.println("Calling printItems(new String[]{\"welcome\", \"to\", \"sdev\", \"220\"})"); - printItems(new String[]{"welcome", "to", "sdev", "220"}); + System.out.println("Calling printItems(new String[]{\"welcome\", \"to\", \"cs\", \"123\"})"); + printItems(new String[]{"welcome", "to", "cs", "123"}); System.out.println(); System.out.println("Calling printItems(new String[]{\"hello\", \"world\"})"); printItems(new String[]{"hello", "world"}); @@ -96,4 +117,4 @@ public static void main(String[] args) { System.out.println("allStartWithA(new String[]{}): " + allStartWithA(new String[]{})); System.out.println(); } -} \ No newline at end of file +}