Skip to content
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand Down
45 changes: 33 additions & 12 deletions src/Practice.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand All @@ -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;
}
}


Expand All @@ -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"});
Expand All @@ -96,4 +117,4 @@ public static void main(String[] args) {
System.out.println("allStartWithA(new String[]{}): " + allStartWithA(new String[]{}));
System.out.println();
}
}
}