http://www.spotify.c...ticket-lottery/

It's very interesting. I finally got all the code up for it, and it seems like I am getting the right answer. But when I submit the code, they tell me it's wrong. Here's my code:

import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; import java.io.InputStreamReader; /** * * @author Rechee Jozil * Written 12/26/2012 */ public class Internship { public static void main(String[] args) throws IOException{ double denomenator = 0.0, numerator = 0.0, probability = 0.0, pEntered = 0.0, winners = 0.0, tickets = 0.0, pGroup = 0.0; BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); //Array list to hold values. ArrayList<Double> lotteryInput = new ArrayList<Double>(); //Add values entered from input stream to arraylist System.out.println("Enter values"); //Split string up String[] st = r.readLine().split(" "); //Parse each element in st into double for(int i = 0; i < 4 ; i++){ lotteryInput.add(Double.parseDouble(st[i])); } r.close(); //Value checking while(lotteryInput.get(0) < 1 || lotteryInput.get(0) > 1000){ System.out.println("Number of people in lottery cannot be less than 1 or more than 100. Enter number of people in lottery again."); Double.parseDouble(r.readLine()); lotteryInput.set(0, pEntered); } while(lotteryInput.get(1) < 1 || lotteryInput.get(1) > lotteryInput.get(0)){ System.out.println("Number of winners cannot be less than 1 or greater than number of people in lottery. Enter number of winners again."); Double.parseDouble(r.readLine()); lotteryInput.set(1, winners); } while(lotteryInput.get(2) < 1 || lotteryInput.get(2) > 100){ System.out.println("Number of tickets cannot be less than 1 or greater than 100. Enter numbef of tickets again. "); Double.parseDouble(r.readLine()); lotteryInput.set(2, tickets); } while(lotteryInput.get(3) < 1 || lotteryInput.get(3) > lotteryInput.get(0)){ System.out.println("Number of people in your group cannot be less than 1 or greater than number of people that entered. Enter number of people in group again. "); Double.parseDouble(r.readLine()); lotteryInput.set(3, pGroup); } //Close buffer r.close(); pEntered = lotteryInput.get(0); winners = lotteryInput.get(1); tickets = lotteryInput.get(2); pGroup = lotteryInput.get(3); //Main for loop for calculation of probablility for(int k = 1; k <= pGroup; k++){ denomenator = (double) (factorial(pEntered) / (double) (factorial(winners) * factorial(pEntered - winners))); numerator = (double) (factorial(pGroup)/ (double) ((factorial(k) * factorial(pGroup - k))) * (double) ((factorial(pEntered - pGroup)) / (double) (factorial(winners - k) * factorial((pEntered - pGroup)- (winners - k))))); probability =probability + ((numerator/ denomenator) * TicketProb(pGroup, k, tickets)); } System.out.println(probability); } // static recursive factorial method static double factorial(double n){ if (n == 0){ return 1; }else{ return n * factorial(n-1); } } static double TicketProb(double x, double y, double z){ if(x <= (y * z)){ return 1.0; } else{ return 0.0; } } }

If you plug in the sample input given by spotify, my answers are the same. Except with the third sample input where mine is 1.0 and there's is 1.0 with 0 repeating.

I think I've covered all angles. I've edited the code several times with no avail. Any body have any insight on how I might solve this problem?