Class CodeCampSummer

java.lang.Object
  extended by CodeCampSummer

public class CodeCampSummer
extends Object


Constructor Summary
CodeCampSummer()
           
 
Method Summary
static int findMajority(int[] list)
          Determine if there is a majority element in an array of ints.
static void main(String[] args)
           
static ArrayList<Integer> matches(String source, String target)
          Find all indices in source that are the start of a complete match of target.
static int mostVowels(String[] list)
          Determine the index of the String that has the largest number of vowels.
static int sharedBirthdays(int numPeople, int numDays)
          Perform an experiment simulating the birthday problem.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CodeCampSummer

public CodeCampSummer()
Method Detail

main

public static void main(String[] args)

matches

public static ArrayList<Integer> matches(String source,
                                         String target)
Find all indices in source that are the start of a complete match of target.

Parameters:
source - != null, source.length() > 0
target - != null, target.length() > 0
Returns:
an ArrayList that contains the indices in source that are the start of a complete match of target. The indices are stored in ascending order in the ArrayList.

mostVowels

public static int mostVowels(String[] list)
Determine the index of the String that has the largest number of vowels. Vowels are defined as 'A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', and 'u'. The parameter list is not altered as a result of this method.

pre: list != null, list.length > 0, there is an least 1 non null element in list

post: return the index of the non-null element in list that has the largest number of characters that are vowels. If there is a tie return the index closest to zero. The empty String, "", has zero vowels. It is possible for the maximum number of vowels to be 0.

Parameters:
list - the array to check
Returns:
the index of the non-null element in list that has the largest number of vowels.

findMajority

public static int findMajority(int[] list)
Determine if there is a majority element in an array of ints. The parameter list is not altered as a result of this method.

Parameters:
list - != null
Returns:
the first index of the value of the majority element if it exists. If a majority element does not exist return -1.

sharedBirthdays

public static int sharedBirthdays(int numPeople,
                                  int numDays)
Perform an experiment simulating the birthday problem. Pick random birthdays for the given number of people. Return the number of pairs of people that share the same birthday.

Parameters:
numPeople - The number of people in the experiment. This value must be > 0
numDays - The number of days in the year for this experiement. This value must be > 0
Returns:
The number of pairs of people that share a birthday.