Question: code should be written in java The purpose of this problem is to practice using a generic Box class. Create a generic class, called Box,
code should be written in java
The purpose of this problem is to practice using a generic Box class.
Create a generic class, called Box, with a type parameterthat simulates drawing an item at random out of a box. 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. Include the following methods in your generic class, along with any other methods youd like:
an add( ) method that allows the user to add oneobject of the specified type
an isEmpty( ) method to determine if the box is empty
a drawItem( ) method that randomlyselects an object from the box and returns it. Return null if the box is empty. Do not delete the selected item. (see Note below)
a toString( ) method.
Your Box class with need an array of size 10 to hold the objects in the box, and a count variable to maintain a count of how many objects are actually in the box.
In the driver file that tests your class create 2 boxes, one with the names of 4 potential study partners from your Math class, the other with numbers between 5 and 10 representing the amount of hours of studying you and your study partner will do
Use the add( ) method to populate the 2 boxes, and the drawItem( ) method for each box to determine i) who your study partner will be and ii) how many hours of studying you and your study partner will do.
Test the isEmpty and toString methods as well for the 2 boxes.
Note:
public int nextInt(int bound) in java.util.Random returns a random int value between 0 (included) and the specified value, bound, (excluded).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
