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

What are access specifiers available in java, What are Access Specifiers av...

What are Access Specifiers available in Java? Java has four access specifiers, which are enlisted below: Public: public methods, classes and fields can be accessed by ever

Develop an online website using java, Project Description: I am planning...

Project Description: I am planning to prepare a website which caters the services to online internet users. I have already prepared most HTML5 pages by own and wanted to impl

Program will compile but wont run , Im receiving an error message of Except...

Im receiving an error message of Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at Homework.main(Homework.java:51)

Explain about the dynamic behavior of core java, This language was designed...

This language was designed to adapt the changing environment and behavior. New methods and instance variables can be added to the client side without any major changes happening at

Solving problems about traffic jam, Computer programming Project Descrip...

Computer programming Project Description: Solving various problems about traffic jam Skills required: C# Programming, Java, C++ Programming, PHP, Software Architecture

Android and universal ios- multipurpose testing app, Android and Universal ...

Android and Universal iOS, Multipurpose Testing App Universal iOS and Android, versatile Testing App Based on Phonegap with the subsequent main features * Support single answ

What are synchronized methods and synchronized statements, What are synchro...

What are synchronized methods and synchronized statements? Synchronized methods are methods that are used to control access to an object. A thread only implements a synchronize

What are the sub categories of artificial intelligence, What are the Sub ca...

What are the Sub categories of Artificial Intelligence? Briefly explain any two? 1. Expert systems: Expert system is in which system that is in some limited sense, could repl

Differentiate local and global variables, Differentiate Local and Global Va...

Differentiate Local and Global Variables? Local variables are the variables have limited scope although global have bigger scope Local variables are not accessed through others

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