Create a generic class with a type parameter, JAVA Programming

1. The purpose of this problem is to practice using generics. 

  • Create a generic class 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 you'd like:
    1. an add( ) method that allows the user to add an object of the specified type
    2. an isEmpty( ) method to determine if the box is empty
    3. adrawItem( ) method that randomly selects an object from the box and returns it. Return null if the box is empty
  • In the driver file that tests your class create 2 boxes, one with the names of 7 friends, the other with numbers between 1 and 5 representing the amount of hours of home work you will do before going to the party you've been invited to. Use the add( ) methods to populate the 2 boxes, and the drawItem( ) methods for each box to determine

i) how many hours of home work you will do before

ii) going to the party with the friend you will invite (from the "friends" box)

Posted Date: 3/21/2013 2:15:35 AM | Location : United States







Related Discussions:- Create a generic class with a type parameter, Assignment Help, Ask Question on Create a generic class with a type parameter, Get Answer, Expert's Help, Create a generic class with a type parameter Discussions

Write discussion on Create a generic class with a type parameter
Your posts are moderated
Related Questions
AskWrite an application that uses an Array to store 10messages of type String. You will store this Array with 10 messages of your choosing. For example, a message could be “I love

I need to code using java in netbeans for my dissertation which is in data mining domain...deals with privacy preserving of sensitive rules or items using association rule hiding

I need a website to do online marketing Project Description: Develop a website designer/developer to develop a website from scratch. This website has to be written in Java an

Does RMI-IIOP support dynamic downloading of classes? Ans) No, RMI-IIOP doesn't support dynamic downloading of the classes as it is complete with CORBA in DII (Dynamic Interface

What is Event Handler works? An event handler is a command which is used to call a function when an event happens, such as the user clicking a button or mouse.

Describe the Superclass in Inheritance ? In this example you start through defining a more common MotorVehicle class. public class MotorVehicle { private String licensePlat

Need assignment help , on the topic “Demonstrate a console-program” Demonstrate a console-program to create an array of integers and Initialize the array and assign the values i

Component Developer to code in Java: Worked for Sansri's Gateway as Software Engineer . Here I Worked as a Component Developer to code in Java and J2EE technologies Here Ensu

Write a CGI program in R, accessible through the class web server, that performs an analysis or creates a graph. You can provide a separate HTML page that displays the initial form

Program 1. Write a Java program to display the first 20 Fibonacci numbers Program with Fibonacci sequence of first 20 terms Output 2. Write an applet progr