Question

In: Computer Science

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 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).

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.
    • See the skeleton below.
  • 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.

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.
  • Gain experience in creating objects and multiple classes.
  • Gain experience in method call using an object of a class written by yourself.

Sample output

The following days have 75 people:

147

The following days have 35 people:

143 312

Solutions

Expert Solution

Program Code Screenshot

Sample Output

Program Code to Copy

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class Arena{
    int people[];
    int capacity;
    Arena(int n){
        capacity = n;
        //Create an array of birthdays
        people = new int[365];
        //Generate random birthdates
        generate();
    }

    void generate(){
        Random r = new Random();
        //Generate birthdays of all people
        for(int i=0;i<capacity;i++){
            people[r.nextInt(365)]++;
        }
    }

    void minDays(){
        //Find day on which there are less birthdays
        int mn = people[0];
        List<Integer> mnl = new ArrayList<>();
        mnl.add(1);
        for(int i=0;i<people.length;i++){
            if(people[i]<mn){
                mn = people[i];
                mnl = new ArrayList<>();
                mnl.add(i+1);
            }
            else if(people[i]==mn){
                mnl.add(i+1);
            }
        }
        System.out.println("The following days have "+mn+" people:");
        for(int x : mnl){
            System.out.print(x+" ");
        }
        System.out.println();
    }

    void maxDays(){
        //Find the day on which there are most birthdays
        int mx = people[0];
        List<Integer> mxl = new ArrayList<>();
        mxl.add(1);
        for(int i=0;i<people.length;i++){
            if(people[i]>mx){
                mx = people[i];
                mxl = new ArrayList<>();
                mxl.add(i+1);
            }
            else if(people[i]==mx){
                mxl.add(i+1);
            }
        }
        System.out.println("The following days have "+mx+" people:");
        for(int x : mxl){
            System.out.print(x+" ");
        }
        System.out.println();
    }
}

class Main{
    public static void main(String[] args) {
        Arena arena = new Arena(12000);
        arena.minDays();
        arena.maxDays();
    }
}

Related Solutions

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...
The Bayside Fountain Hotel is adjacent to County Coliseum, a 24,000?seat arena that is home to...
The Bayside Fountain Hotel is adjacent to County Coliseum, a 24,000?seat arena that is home to the city’s professional basketball and ice hockey teams and that hosts a variety of concerts, trade shows, and conventions throughout the year. The hotel has experienced the following occupancy rates for the past 9 years, since the coliseum opened: 1..............83 2..............78 3..............75 4..............81 5..............86 6..............85 7..............89 8...............90 9...............86 a.Use Excel and POM?QM to compute an exponential smoothing forecast with ? = .20, an adjusted...
Create a PowersTable application that displays a table of of powers. ( Java Programing )
Create a PowersTable application that displays a table of of powers. ( Java Programing )
David Stern, Commissioner of the National Basketball Association (NBA), scanned the arena from his courtside seat...
David Stern, Commissioner of the National Basketball Association (NBA), scanned the arena from his courtside seat at the sold out Toyota Center in Houston, TX during the 2004 Western Conference Playoffs game between the Houston Rockets and the Los Angeles Lakers. The video commercials and fan-response prompts he viewed on the high-tech scoreboard reminded him of how far technology had progressed since he first took the helm of the league in 1984. The NBA’s tremendous growth that stemmed from increased...
Advance programing in java Qn1 1.True or False: (a) A sequence of 0s and 1s is...
Advance programing in java Qn1 1.True or False: (a) A sequence of 0s and 1s is called a decimal code. (b) ZB stands for zero byte. (c) The CPU stands for command performing unit. (d) Every Java application program has a method called main. (e) An identier can be any sequence of digits and letters. (f) Every line in a program must end with a semicolon. 2. Explain the two most important benets of the Java language 3 Explain the...
programing language JAVA: Design and implement an application that reads a sentence from the user, then...
programing language JAVA: Design and implement an application that reads a sentence from the user, then counts all the vowels(a, e, i, o, u) in the entire sentence, and prints the number of vowels in the sentence. vowels may be upercase
java programing project Implement a program that computes the Fibonacci of a specified number, the factorial...
java programing project Implement a program that computes the Fibonacci of a specified number, the factorial of a specified number, or estimates the value of 'e' using the specified number of iterations (of a Taylor series). Please feel free to use the Internet to find resources that explain how to estimate the value of 'e' using a Taylor series. In the case of no or invalid number of parameters, the program should show help instructions that looks like: --- Assign...
Java Programing: Predefined mathematical methods that are part of the class Math in the package java.lang...
Java Programing: Predefined mathematical methods that are part of the class Math in the package java.lang include those below. method name description abs( m ) returns the absolute value of m ceil( m ) rounds m to the smallest integer not less than m floor( m ) rounds m to the largest integer not greater than m max( m , n ) returns the larger of m and n min( m , n ) returns the smaller of m and...
JAVA PROGRAMING In a particular factory,a shift supervisor is a salaried employee who supervises a shift.In...
JAVA PROGRAMING In a particular factory,a shift supervisor is a salaried employee who supervises a shift.In addition to a salary,the shift supervisor earns a yearl bonus when his or her shift meets production goals.Design a ShiftSupervisor class that extends the Employee class. TheShiftSupervisor class should have a field that holds the annual salary and a field that holds the annual production bonus that a shift supervisor has earned.Write one or more constructor and the appropriate accessor and mutator methods for...
This is Java Programing. Add a shape of oval to BOXBALLOVAL. import java.awt.*; import java.awt.event.*; import...
This is Java Programing. Add a shape of oval to BOXBALLOVAL. import java.awt.*; import java.awt.event.*; import java.util.*; import java.util.Timer; import javax.swing.*; public class BOXBALLOVAL {    public static void main(String[] args) { new myframe();// creating main jframe instance    } } class myframe extends JFrame {    Container c;    JPanel panel;    JButton addbutton, removebutton;    JLabel counter, ballsize;    JTextField size_input;    JComboBox cb;    buttonListener handle;    myDrawboard myboard;    JFrame mainFrame;    public myframe()    {...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT