Instructions Carefully read the program requirements. All .java files are requir
ID: 3642866 • Letter: I
Question
InstructionsCarefully read the program requirements. All .java files are required to be uploaded to Angel in a single .zip file by the start of class the following week. Late exams will not be accepted and receive a grade of 0%. Please do not email your programs to me personally or via Angel after the dropbox closes; they will not be accepted. The Angel dropbox is the required method of submission.
All work is to be your own. There is no collaboration allowed and the discussion board will be removed from Angel. This is a take-home Final Exam programming assignment.
Program Requirements
You will be creating a text-based program called the
Explanation / Answer
please rate
===================
BirthdayParadox.java
===================
package birthdayParadox;
import java.util.Random;
public class BirthdayParadox {
int noOfpeople;
long noOfRuns;
int[] birthDates;
Random r = new Random();
private boolean isDuplicate(){
boolean result = false;
for(int i=0;i<noOfpeople;i++){
for(int j=0;j<i;j++){
if(birthDates[i]==birthDates[j]){
return true;
}
}
}
return result;
}
public BirthdayParadox(int noOfPeople,long numberOfRuns){
this.noOfpeople = noOfPeople;
this.noOfRuns = numberOfRuns;
birthDates = new int[noOfPeople];
}
private void fillBirthDates(){
for(int i=0;i<noOfpeople;i++){
birthDates[i] = r.nextInt(366);
}
}
public double runBirthdayParadox(){
double result = 0.0;
for(long i=0;i<noOfRuns;i++){
fillBirthDates();
if(isDuplicate())
result += 1;
}
result = result / noOfRuns;
return result;
}
}
======================
BirthdayParadoxTest.java
=======================
package birthdayParadox;
public class BirthdayParadoxTest {
public static void main(String[] args){
long numberOfRuns = 1000000;
int people1 = 23;
int people2 = 57;
BirthdayParadox p1 = new BirthdayParadox(people1, numberOfRuns);
BirthdayParadox p2 = new BirthdayParadox(people1, numberOfRuns);
BirthdayParadox p3 = new BirthdayParadox(people1, numberOfRuns);
BirthdayParadox p4 = new BirthdayParadox(people2, numberOfRuns);
BirthdayParadox p5 = new BirthdayParadox(people2, numberOfRuns);
BirthdayParadox p6 = new BirthdayParadox(people2, numberOfRuns);
System.out.println(people1+" people "+p1.runBirthdayParadox());
System.out.println(people1+" people "+p2.runBirthdayParadox());
System.out.println(people1+" people "+p3.runBirthdayParadox());
System.out.println(people2+" people "+p4.runBirthdayParadox());
System.out.println(people2+" people "+p5.runBirthdayParadox());
System.out.println(people2+" people "+p6.runBirthdayParadox());
}
}