Create a generic class with a type parameter, JAVA Programming

Assignment Help:

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)


Related Discussions:- Create a generic class with a type parameter

Program to calculates the number of unique shapes, 1. Write the code for th...

1. Write the code for the method that calculates the number of unique shapes for a binary search tree with n nodes. Use the formula  where b n is the number of possible sh

What is a socket in java networking and rmi, A socket is one end-point of a...

A socket is one end-point of a two-way communication link among two programs running on the network. A socket is bound to a port number so that the TCP layer can recognize the appl

What should be output of above code, Number = new Array(5); var abc=4; for(...

Number = new Array(5); var abc=4; for(var i=1; i { Number[i]= abc*i; } Number.reverse(); for(j=0;j { document.write(" "+Number[j]+" "); } A) What should be output of above co

Explain rmi architecture, RMI uses a layered architecture; every of the lay...

RMI uses a layered architecture; every of the layers could be increased or replaced without affecting the rest of the system. The details of layers can be summarised as follows:

JAVA APPLET GAMES, WHAT IS THE INTRODUCTION OF JAVA APPLET GAMES IN CONNECT...

WHAT IS THE INTRODUCTION OF JAVA APPLET GAMES IN CONNECT4

Prepare a game in corona, Prepare a Game in Corona (for Android and IOS) ...

Prepare a Game in Corona (for Android and IOS) Project Description: We are looking to prepare a game for mobile platform similar to Zombie Smasher for iOS and Android. Eve

What do you mean by java virtual machine?, Question 1 What do you mean by ...

Question 1 What do you mean by Java Virtual Machine? Question 2 Write a simple Java program to display a string message and explain the steps of Compilation and execution in Jav

Java identifiers and variable class, 1. Which of the following are not vali...

1. Which of the following are not valid Java identifiers, and why? (a) wolVes (b) United(there is only one) (c) 87 (d) 5 3 (e) Real ale (f) isFound?by 2. A cla

For in statement, It is a distinct type of loop, used to iterate through th...

It is a distinct type of loop, used to iterate through the properties of an object or the elements of an array. For instance assume the following statement that loops through th

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd