Git-Leon 2b30deca0d
Update README.md
6 yıl önce
src first commit 6 yıl önce
.gitignore first commit 6 yıl önce
README.md Update README.md 6 yıl önce
pom.xml first commit 6 yıl önce

README.md

Building Utility Class for String Array Objects

  • Objective

    • Ensure StringArrayUtilsTest passes each test by completing the methods stubbed out in the class StringArrayUtils
      • int getNumberOfOccurrences(String[] stringArray, String stringToCheck)
      • boolean contains(String[] stringArray, String stringToCheck)
      • String[] removeValue(String[] stringArray, String stringToRemove)
  • Purpose

    • To establish greater familiarity with loops and arrays.
    • To demonstrate the implementation of a Utility class





Sample Behavior
removeValues(array, valueToRemove)

  • Description
    • Given an array of String objects named array and a String object named valueToRemove
      create and return an array containing identical contents excluding objects whose value is equivalent to valueToRemove. Ensure that the length of the newly created array has been resized based on the removal of the undesired elements.

Example 1

  • Sample Script

    // : Given
    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
        
    // : When
    String[] actual = StringArrayUtils.removeValues(array, "aba");
        
    // : Then
    System.out.println(Arrays.toString(actual));
    
  • Sample Output

    [baa, bab, bba, bba, bba, bba, bbb, bbb};
    

Example 2

  • Sample Script

    // : Given
    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
        
    // : When
    String[] actual = StringArrayUtils.removeValues(array, "bba");
        
    // : Then
    System.out.println(Arrays.toString(actual));
    
  • Sample Output

    [aba, aba, baa, bab, bbb, bbb];
    

Example 3

  • Sample Script

    // : Given
    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
        
    // : When
    String[] actual = StringArrayUtils.removeValues(array, "bbb");
        
    // : Then
    System.out.println(Arrays.toString(actual));
    
  • Sample Output

    [aba, aba, baa, bab, bba, bba, bba, bba];
    





Sample Behavior
getNumberOfOccurrences(array, value)

  • Description
    • Given an array of String objects named array and a String object named value
      return the number of times value appears in arrays

Example 1

  • Sample Script

    // : Given
    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
        
    // : When
    int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "bba");
        
    // : Then
    System.out.println(numberOfOccurrences);
    
  • Sample Output

    4
    

Example 2

  • Sample Script

    // : Given
    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
        
    // : When
    int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "bbb");
        
    // : Then
    System.out.println(numberOfOccurrences);
    
  • Sample Output

    2
    

Example 3

  • Sample Script

    // : Given
    String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
        
    // : When
    int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "baa");
        
    // : Then
    System.out.println(numberOfOccurrences);
    
  • Sample Output

    1
    





Sample Behavior
contains(array, value)

  • Description

    • Given an array of String objects named array and a String object named value
      return true if value appears in arrays.

      Example 1

  • Sample Script

    // : Given
    String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
        
    // : When
    boolean outcome = StringArrayUtils.contains(array, "the");
        
    // : Then
    System.out.println(outcome);
    
  • Sample Output

    true
    

Example 2

  • Sample Script

    // : Given
    String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
        
    // : When
    boolean outcome = StringArrayUtils.contains(array, "potatoes");
        
    // : Then
    System.out.println(outcome);
    
  • Sample Output

    false