Question: The purpose of this problem is to practice using generics. Create a generic class, called Box, with a type parameter that simulates drawing an item

The purpose of this problem is to practice using generics.

Create a generic class, called Box, with a type parameter that 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 one object of the specified type

an isEmpty( ) method to determine if the box is empty

a drawItem( ) method that randomly selects 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 computer class, the other with numbers between 5 and 10 representing the amount of hours of studying you and your study partner will do in preparation for the upcoming test.

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.

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!