Question

In: Computer Science

In Java, write a program that solves the following problem. An arena can seat 12,000 people...

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 Main class will hold the main() method.
    • From this class, you will create an object of the Arena class.
    • This object will call responsible methods in the Arena class to print the MAX and MIN birthday dates.
  • the Arena class will have a random number generation method.
    • This class's constructor will take #of people in the area as an input.
    • With this number, you will create an array and a method will put random numbers between 1 and 365 in this array.
    • Two other methods in this class will determine the days with MAX and MIN birthdays.
    • Make sure to print ALL maximum and minimum birthdate days.

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

Solutions

Expert Solution

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


Related Solutions

Programing Java The school Arena can seat 12,000 people for an event. If the arena was...
Programing Java The school 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...
Write a program that solves the Knapsack problem. Code to the following standards. Your source of...
Write a program that solves the Knapsack problem. Code to the following standards. Your source of items to put into the knapsack should consist of five randomly generated integers in the range of 1 to 20. Your knapsack can hold 20 lbs.
Scenario You are the senior event services manager for a 12,000-seat arena located on a major...
Scenario You are the senior event services manager for a 12,000-seat arena located on a major university campus in the southeastern United States. The university’s athletics teams compete in the powerful Atlantic Coast Conference (ACC). On this particular Saturday afternoon, the university men’s basketball team is playing a home game against one of its fiercest ACC rivals. In fact, the visiting team is the defending NCAA national champion and the fans were in a frenzied state for this game when...
Write a program in C++ that solves this problem Calculate the area and volume of a...
Write a program in C++ that solves this problem Calculate the area and volume of a sphere problem. Inside a for loop, vary the radius from 10 to 40  with a step or increment of 5 and calculate the area and volume Your radius will be equal to your loop counter. All calculations should have 2 decimal places, but the radius should have zero decimal places and any number of 1,000 or more should have a comma. Print the radius, area,...
A Java program that solves a real-world problem The remaining amount (balance) for a prepaid cellular...
A Java program that solves a real-world problem The remaining amount (balance) for a prepaid cellular phone, is computed by subtracting the cost of the phone usage from the original phone load. The phone usage is based only on the total cost of text messages and phone calls. The cost of text messages is determined from the number of text messages sent and the cost of phone calls is determined from the number of minutes of calls made. ● Based...
Write a Java program that solves a set of quadratic equations as per Requirement #1 (without...
Write a Java program that solves a set of quadratic equations as per Requirement #1 (without using global variables), and reads an integer number entered in the command line, as follows: > java program_name input_number and depending on the value of this number does the following: 1) If the number entered is positive, the program shall solve (running in a loop) as many quadratic equations of the following form, as the input_number tells: a * x2 + b * x...
Java Palindrome (Timelimit: 10seconds) Problem Description Write a Java program to solve the following problem. A...
Java Palindrome (Timelimit: 10seconds) Problem Description Write a Java program to solve the following problem. A palindromic number is an integer that is the same when the digits are reversed. For example, 121 and 625526 are palindromic, but 625 is not a palindromic number. Input: The input is in ‘palindrome.txt’. The first line of the input contains the line count m (1 ≤ m ≤ 1,000), which is the number of lines that follows the first line. Each of the...
Java Recursion (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem....
Java Recursion (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem. Recursion may appear in various contexts and in different forms. For fast implementation, we should always aim at transforming recursions into a simpler form of computation. In this assignment, the task is to evaluate X(·), which is defined as follows:               |0,if m = 0 or n = 0               | X(m,n−1),if n is odd and m is even X(m,n) = | X(m−1,n),if m...
Write two Java programs ( Iterative and Recursive programs ) that solves Tower of Hanoi problem?use...
Write two Java programs ( Iterative and Recursive programs ) that solves Tower of Hanoi problem?use 4 disks and 3 bars
Write two Java programs ( Iterative and Recursive programs ) that solves Tower of Hanoi problem?use...
Write two Java programs ( Iterative and Recursive programs ) that solves Tower of Hanoi problem?use 4 disks and 3 bars. Students must send the code and outputs
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT