Question: In Java, use ArrayList for the data structure. Each year, Sleepy Hollow Elementary School holds a Principal for a Day lottery. A student can participate
In Java, use ArrayList for the data structure. Each year, Sleepy Hollow Elementary School holds a "Principal for a Day" lottery. A student can participate by entering his/her name and ID number into a pool of candidates. The winner is selected randomly from all entries. Each student is allowed one entry.
To help you test your code, please use the following data sample:
| Name | ID number |
|---|---|
| Bobby Drake | 08456 |
| Jean Grey | 84691 |
| Hank McCoy | 34976 |
| Scott Summers | 61851 |
| Warren Worthington III | 76182 |
| Charles Xavier | 05973 |
To create a code to accomplish, it needs to include the following:
- Implement a class StudentLottery, with methods that: enter students in the "Principal for a Day" lottery and pick a winner from the entries
- The application should check that no student enters the lottery more than once
- The Student class encapsulates a student. A student object holds a student's name as well as his/her number
- The Student class has the usual getter and setter methods
- Student overrides the equals(Object o) method inherited from Object so that two students are equal if they have the same name and ID number
- The StudentLottery class uses an ArrayList, entries to hold Student references.
- The Student Lottery class has methods:
- void addStudents() that enters students in the lottery and
- voidpickWinner() that uses the Random class to select one winner from among all Student entries
- The addStudents() method checks that there are no duplicate entries.
- When all students are entered, the name of the winning student and his/her ID are display
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
