Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The CenturyLink Center can seat 18,975 people for an event. If the arena was ful

ID: 3566888 • Letter: T

Question

The CenturyLink Center can seat 18,975 people for an event. If the arena was full and you were to poll everyone for which day of
the year (1-365) they were born, determine which days had the most birthdays and which days had the fewest birthdays.
Write a program that will generate 18,975 random birthdays (numbers) between 1 and 365 and count how many people have that
same birthday. Output a display of each day of the year (1 365) followed by the number of people with that birthday, and then 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).
Goals
Use your knowledge of arrays and random number generation to solve a problem.
Use looping structures to determine the largest and smallest values in an array and then find each occurrence of that value.

Points to Think About
A solution with just a main() method would likely contain five looping structures. The first would fill an array of counters
based on random numbers between 1 and 365. The next two would first identify the largest value (count) stored in the
array and then go back through the array and identify the positions (days) that contained that value, outputting the
positions. The last two would first identify the smallest value (count) stored in the array and then go back through the
array and identify the positions (days) that contained that value, outputting the positions.

Sample Program Run (no user input)
Days 1 through 310 of the output omitted for brevity
Day 311 : 50 people
Day 312 : 35 people
Day 313 : 48 people
Day 314 : 52 people
Day 315 : 56 people
Day 316 : 60 people
Day 317 : 61 people
Day 318 : 59 people
Day 319 : 44 people
Day 320 : 43 people
Day 321 : 52 people
Day 322 : 48 people
Day 323 : 38 people
Day 324 : 45 people
Day 325 : 63 people
Day 326 : 53 people
Day 327 : 49 people
Day 328 : 54 people
Day 329 : 49 people
Day 330 : 54 people
Day 331 : 41 people
Day 332 : 54 people
Day 333 : 59 people
Day 334 : 59 people
Day 335 : 52 people
Day 336 : 55 people
Day 337 : 50 people
Day 338 : 50 people
Day 339 : 46 people
Day 340 : 50 people
Day 341 : 68 people
Day 342 : 50 people
Day 343 : 57 people
Day 344 : 49 people
Day 345 : 44 people
Day 346 : 55 people
Day 347 : 40 people
Day 348 : 52 people
Day 349 : 36 people
Day 350 : 43 people
Day 351 : 42 people
Day 352 : 50 people
Day 353 : 52 people
Day 354 : 48 people
Day 355 : 68 people
Day 356 : 41 people
Day 357 : 40 people
Day 358 : 41 people
Day 359 : 46 people
Day 360 : 60 people
Day 361 : 42 people
Day 362 : 65 people
Day 363 : 57 people
Day 364 : 54 people
Day 365 : 48 people
The following days have 75 people:
147
The following days have 35 people:
143 312

Explanation / Answer

//import Random class
import java.util.Random;
//class CenturyLinkCenter
public class CenturyLinkCenter {
   //main method
   public static void main(String[] args) {
       //The Days Array has 18975 elements
       int Days[] = new int[18975];
       //Count Array has 365 elements
       int count[] = new int[365];
       //create an instance to Random class
       Random r = new Random();
       //local declaration
       int Low = 1;
       int High = 366;
       int R;
       //generate a Random number between 1 - 18975 and store in Days.
       for (int i = 0; i < 18975; i++) {
           R = r.nextInt(High - Low) + Low;
           Days[i] = R;
       }

       //set count to 0
       for (int i = 0; i < 365; i++)
           count[i] = 0;

       //increment the count for the respective days
       for (int i = 0; i < 18975; i++) {
           // System.out.println(""+Days[i]);
           count[Days[i] - 1]++;
       }

       //print the result
       for (int i = 0; i < 365; i++)
           System.out.println("Day " + (i + 1) + " has " + count[i]+ " birthdays");
      
       int small = 400;
       int large = 0;
       int smallIndex = 0,largeIndex = 0;
      
       for (int i = 0; i < 365; i++)
       {
           if(count[i] < small)
           {
               small = count[i];
               smallIndex = i+1;
           }
           if(count[i] > large)
           {
               large = count[i];
               largeIndex = i+1;
           }
       }
      
       System.out.println("The day"+largeIndex+" has more number of birthdays("+large+")");
       System.out.println("The day"+smallIndex+" has less number of birthdays("+small+")");
   }

}

-------------------------------------------------------------------------------------------------------------

Sample Output:

Day 1 has 51 birthdays
Day 2 has 47 birthdays
Day 3 has 70 birthdays
Day 4 has 46 birthdays
Day 5 has 56 birthdays
Day 6 has 50 birthdays
Day 7 has 57 birthdays
Day 8 has 60 birthdays
Day 9 has 47 birthdays
Day 10 has 50 birthdays
Day 11 has 40 birthdays
Day 12 has 54 birthdays
Day 13 has 47 birthdays
Day 14 has 60 birthdays
Day 15 has 60 birthdays
Day 16 has 58 birthdays
Day 17 has 49 birthdays
Day 18 has 52 birthdays
Day 19 has 58 birthdays
Day 20 has 48 birthdays
Day 21 has 56 birthdays
Day 22 has 54 birthdays
Day 23 has 50 birthdays
Day 24 has 58 birthdays
Day 25 has 49 birthdays
Day 26 has 54 birthdays
Day 27 has 49 birthdays
Day 28 has 49 birthdays
Day 29 has 41 birthdays
Day 30 has 58 birthdays
Day 31 has 59 birthdays
Day 32 has 56 birthdays
Day 33 has 57 birthdays
Day 34 has 73 birthdays
Day 35 has 52 birthdays
Day 36 has 47 birthdays
Day 37 has 54 birthdays
Day 38 has 53 birthdays
Day 39 has 51 birthdays
Day 40 has 51 birthdays
Day 41 has 50 birthdays

.

.

.

.

The day 264 has more number of birthdays(70)
The day 287 has less number of birthdays(35)