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
Need to develop a Small Android App using Text to speech and Speech to Text feature. Project Description: When the Android App Opens, It will connect to Windows Azure cloud,

Relate in brief - Microsoft vs Java Microsoft hates Java, as a Java program (portable) isn't tied to any particular operating system. If Java is popular, then programs written

Describe Unbalanced Arrays ? Such as C Java does not have true multidimensional arrays. Java fakes multidimensional arrays by using arrays of arrays. This means that it is prob

Write a Java REST client to perform the following- The client will read the contents of the file - invoice.txt. The first line of the file will display the type of the currency.

What Can an Applet Do? An applet can: • Draw pictures on a web page • Create a new window and draw in it. • Play sounds. • Receive input from the user by the keyboard or

please help please help please help please help please help please helpplease help please help

How is method overriding different from method overloading? Overriding involves the creation of two or more concepts with the same name and same signature in different classes

i) Set the number of data points to 20 and the number of clusters to 2. Check box Show History. Click on Initialize. Click on Start. Click on Step . Observe which points ch

J2EE (Java 2 Enterprise Edition) is an environment for deploying and developing enterprise applications on various operating system. The J2EE platform consists of J2EE components,

How to Creating Arrays in java? Declaring arrays merely says what type of values the array will hold. It does not form them. Java arrays are objects, and such as any other obje