In: Computer Science
In Java, write a program that solves the following problem.
An arena can seat 12,000 people for an event. If the arena was full and you were to poll everyone for which day of the year (between 1 and 365, inclusive) they were born, determine which days had the most birthdays and which days had the fewest birthdays.
Write a program that will generate 12,000 random birthdays (integer numbers) between 1 and 365 and count how many people have that same birthday. Output a listing of the days that have the most birthdays and the days that have the fewest birthdays. You do not need to convert a number like 32 to an actual date (February 1st).
Do NOT change your class name from "Main". Your filename should be "Main.java".
Your code will have two classes:
The two classes can be part of the same file. A naive example structure is shown below.
public class Main{
public static void main(String args[]){
Arena a = new Arena();
a.printArena();
}
}
class Arena{
void printArena() {
System.out.println("I am arena");
}
}
Sample Output
The following days have 75 people:
147
The following days have 35 people:
143 312
Java code
============================================================================================
import java.util.*;
class Arena{
int days[]=new int[366];
Arena(int people)
{
Random rand = new Random();
for(int i=0;i<people;i++)
{
int
t=rand.nextInt(365) + 1;
days[t]++;
}
}
void maxBirthday()
{
int max=days[1];
int i;
for(i=1;i<366;i++)
{
if(days[i]>max)
{
max=days[i];
}
}
System.out.println("The following
days have "+max +" people:");
for(i=1;i<366;i++)
{
if(days[i]==max)
System.out.print(i+" ");
}
}
void minBirthday()
{
int min=days[1];
int i;
for(i=1;i<366;i++)
{
if(days[i]<min)
{
min=days[i];
}
}
System.out.println("\nThe following
days have "+min +" people:");
for(i=1;i<366;i++)
{
if(days[i]==min)
System.out.print(i+" ");
}
}
}
public class Main{
public static void main(String[] args) {
// TODO Auto-generated method
stub
Arena a = new Arena(12000);
a.maxBirthday();
a.minBirthday();
}
}
============================================================================================
Output
