Question
In Java, create a generic class DrawingBox with a type parameter that simulates drawing an item at random out of a box. This class could
In Java, create a generic class DrawingBox with a type parameter that simulates drawing an item at random out of a box. This class could be used for simulating a random drawing. For example, the box might contain Strings representing names written on a slip of paper, or the box might contain Integers representing a random drawing for a lottery based on numeric lottery picks. Create an add method that allows the user of the class to add an object of the specified type along with an isEmpty method that determines whether or not the box is empty. Finally, your class should have a drawItem method that randomly selects an object from the box and returns it. If the user attempts to draw an item out of an empty box, return null.
Create two input files, inputS and inputI, which contains 50 character strings and 50 integers, respectively. Write a main method that reads inputS (respectively, inputI) and insert the strings (resp. integers) into the drawingbox using the add method. Then perform 3 random drawing and print out the results for each of the two drawingboxes. To generate a random number x, where 0 x 1, use x = Math.random(). Then, convert x into an integer in the range between 0 and 50.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started