Question: Create a generic class, called Case, with a generic type parameter that simulates drawing an item at random out of a Case. For example the

Create a generic class, called Case, with a generic type parameter that simulates drawing an item at random out of a Case. For example the Case might contain Strings representing names written on a slip of paper, or the Case 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. Attempting to add too many items to the Case will throw a FullCaseException to the application
an isEmpty() method (returns true if the Case is empty, otherwise returns false)
a drawItem() method that randomly (see Note below) selects an object from the Case and returns it. Delete the selected item do not store a null in this spot. You must fill this gap by shuffling items one index to the left, or by putting the last item in this spot. Whatever strategy you use, the last filled index of the array will be made null. Attempting to draw from an empty Case will throw an EmptyCaseException to the application
a toString() method (returns a String containing the Cases contents). If the Case is empty the toString should return the Case is empty
Your Case class with need an array of size 10(a FIXED size) to hold the objects in the Case, and a count variable to maintain a count of how many objects are actually in the Case.
Also create a generic interface, called CaseADT, with a generic type parameter. Include the method headers for the methods described above that will be in the Case class. The Case class should implement the CaseADT interface.
In the driver file that tests your class create 3 Cases, one to test all the methods in the Case class, one with the names of 5 of your friends, the third with numbers between 5 and 14 inclusive representing the number of hours you will spend studying for the final exam with 2 of your friends.
For the test Case,
before you put anything in it, call the isEmpty method, the toString method and the drawItem method and show what output each method produces.
create a for loop to attempt to add 11 integers to the Case. Your code should catch the exception and write out an appropriate message
call the toString to display the contents of the Case after youve added 10 items
create a for loop to attempt to draw 11 items out of the Case. After each draw print out the item that is drawn, and call the toString() to display the contents of the Case after that draw. Your code should demonstrate:
o each item drawn is random
o each item drawn is different
o attempting to draw the 11th item should throw an exception. Your code should catch the exception and write out an appropriate message
o call the toString once the loop is done to display the contents of the now empty Case
For the remaining 2 Cases, use the add() method to populate the 2 Cases, and the drawItem() method for each Case to determine i) which 2 friends you will study with and ii) how many hours you and your friend will be studying for the final.
Remember to include lots of descriptive comments in your output.
Notes:
public int nextInt(int bound) in java.util.Random returns a random int value between 0(included) and the specified value, bound, (excluded).
You create a Case object containing int values using this syntax:
Case test = new Case();
Remember that some class type must be used to replace T in the generic class, so the int data type can not be used
If you use this syntax Case test = new Case(); Java will use the Object type by default which defeats the purpose of using generics

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!