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
Project Description: Two co-founders are in search of a developer to join us to launch a tech startup. We have experience at fortune 500 companies, elite consulting firms, etc.,

The game of Kala is played on a rectangular board: In front of each player are six pits numbered 1 to 6 (called the 'side pits'). To the right of a player's side pits is a


I neeed to create a basic code to do the following. the class is entry level and I would appreciate a brief explanation as to why you do each bit. Write a program that displays t

An application server cluster has of a number of application servers loosely coupled on a network. The server group or server cluster is usually distributed over a number of nodes

We need a Java Developer a) Having 4.6 years of I.T experience Java, J2EE, spring, Hibernate, JSF, Swings. b) Analyze, identifying and understanding the client requirements a

Question: a) Give a detailed description of your understanding concerning "Managing User Sessions and Open files". b) What is "Overriding Inheritance" and how can it be do

Problem 1 A savings account object holds a non-negative balance, and provides deposit(k ) and withdraw(k ) methods, where deposit(k ) adds k to the balance, and withdraw(k ) subtra

I want Crime Management website Project Description: It is a web based project build in J2EE as front end and Oracle as back end for peoples so they will register complaints

Explain Subclasses and Polymorphism ? Car and Motorcycle are subclasses of MotorVehicle. If you instantiate a Car or a Motorcycle along with new, you can use in which object a