I did eventual figure this out after getting my head wrapped around it.
import javax.swing.JOptionPane;
public class BDayMTester{
public static void main(String[] args){
final int trials = 10000;
String duplicateCt = JOptionPane.showInputDialog("Enter duplicate count");
String peopleCt = JOptionPane.showInputDialog("Now enter the number of people in the room");
int dupCt = Integer.parseInt(duplicateCt);
int pplCt = Integer.parseInt(peopleCt);
// Creates a new BDayM object with user inputed values
BDayM b = new BDayM(pplCt, dupCt);
int match = 0;
// Goes through the set number of trials determining
// how many true outcomes occur.
for(int j=0; j<trials; j++){
if(b.runTest() == true){
match++;
}
}
double toPercent = ((double)match/trials)*100;
System.out.println("Match chance for " + pplCt + " people: looking for " + dupCt + " duplicates");
System.out.println((double)match/trials);
System.out.println(toPercent + "%");
}
}
public class BDayM{
private int roomFolks;
private int dupPeople;
private int s = 0;
public BDayM(int people, int duplicates){
roomFolks = people;
dupPeople = duplicates;
}
public boolean runTest(){
int[] count = new int[30]; // array to hold each possible day
// This for loop generates a random day of the month for each person
// then applies that day to the counter array which keeps track of
// how many birthdays are on each day.
for(int j = 0; j<roomFolks; j++){
s = genDay();
count[s]++;
}
// This for loop goes through each counter array index and checks if that
// index meets the condition of being at least the value dupPeople (which
// is inputed by the user in the BDayTester class).
for(int n=0; n<30; n++){
if(count[n] >= dupPeople){
return true; // If the condition is met, runTest() returns true
}
}
return false; //otherwise runTest() will retun false
}
// Calculates a random day 0-29 for use in the runTest() method
private int genDay(){
return((int)(30*Math.random()));
}
}