answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alex Ar [27]
2 years ago
7

Create a generic class Box with a type parameter that simulates drawing an item at random out of a box. This class could be used

for simulating a random drawing. 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 based on numeric lottery picks. Create an add() method that allows the user of the class to add an object of the specified type along with size() and isEmpty() method. The former method returns the number of items in the box. Tha latter method determines whether or not the box is empty. Finally, your class should have a drawItem() method that randomly selects an object from the box and returns it (the item is removed from the box). If the user attempts to draw an item out of an empty box, return null. Note that we want the size of the box to be dynamic. In other words, there should not be a hard limit on the size of the box. The user can insert only a few or a large number of items. What is a good option here

Computers and Technology
1 answer:
NikAS [45]2 years ago
8 0

Answer:

Check the explanation

Explanation:

//*********** Box.java *********

import java.util.ArrayList;

public class Box<T> {

   ArrayList<T> items=new ArrayList<T>();

   public void add(T item)

   {

       items.add(item);

   }

   public boolean isEmpty()

   {

       return items.isEmpty();

   }

   public T drawItem()

   {

       int randomIndex=(int)(Math.random()*items.size());

       return items.get(randomIndex);

   }

}

//*********** Driver.java *********

public class Driver {

   public static void main(String args[])

   {

       Box<String> partners=new Box();

       Box<Integer> hours=new Box();

       String x="John";

       String y="Tom";

       String z="Annie";

       partners.add(x);

       partners.add(y);

       partners.add(z);

       hours.add(5);

       hours.add(6);

       hours.add(7);

       hours.add(8);

       hours.add(9);

       hours.add(10);

       String study_partner=partners.drawItem();

       int study_hours=hours.drawItem();

       System.out.println("Study partner: "+study_partner);

       System.out.println(("Study hours: "+study_hours));

   }

}

Kindly check the attached image below to see the output.

You might be interested in
ANSWER AS SOON AS POSSIBLE: When I try to join roblox adopt me it says: "Roblox Datastore servers are currently down. Please rej
masha68 [24]
Bro This is homework no roblox
7 0
2 years ago
Read 2 more answers
The second version of css, css2, was introduced in 1998, expanding the language to provide styles to _________.
Evgen [1.6K]

Answer:

Structured Documents

Explanation:

Structured Documents consist of hierarchy in the files. They may include data files. HTML (Hyper-text markup language) documents and XML (Extensible Markup Language) applications are the examples of Structured Documents.

6 0
2 years ago
All the employees of Delta Corporation are unable to access the files stored in the server. What do you think is the reason behi
CaHeK987 [17]
C serve crash hope this is correct
5 0
2 years ago
Pick the correct statements regarding cell references.
shusha [124]

Statement two and three is correct.

Statement 1 is incorrect. A relative reference changes when a formula is copied to another cell while Absolute references remain constant. However, it is safe to say that an absolute address can be preceded by a $ sign before both the row and the column values. It is designated by the addition of a dollar sign either before the column reference, the row reference, or both. Statement C is also correct. A mixed reference is a combination of relative and absolute reference and the formula (= A1 + $B$2) is an example of a mixed cell reference.

7 0
2 years ago
Read 2 more answers
Which organization supports professionals who assist families in making informed choices about products and services?
Naily [24]
The organisation that would best aid families and choose the right products to buy would be the American Association of Family and Consumer Sciences. In addition, the institution is primarily composed of home economists wherein these professionals promote efficient consumer consumption of goods.
6 0
2 years ago
Read 2 more answers
Other questions:
  • When seeking information on the internet about a variety of subjects the most useful place to look would be?
    13·2 answers
  • In which of these places might you be most likely to find a peer-to-peer network? On the Internet In a hospital In a home In a l
    5·2 answers
  • Copy the 10 statements as they appear below into your journal.
    6·2 answers
  • Prompt: Which references and reference formats are you most likely to use? Why?<br><br><br> ED2020
    13·2 answers
  • Matt is a senior developer for Cyber Protect, a company that helps secure management information systems. Matt's new task is to
    8·1 answer
  • In this exercise, you will create a couple of helper methods for ArrayLists in a class called ArrayListMethods.
    10·1 answer
  • Two-dimensional array indexes are listed as
    8·1 answer
  • Java Programming home &gt; 1.14: zylab training: Interleaved input/output Н zyBooks catalog Try submitting it for grading (click
    6·1 answer
  • Create a different version of the program that: Takes a 3-digit number and generates a 6-digit number with the 3-digit number re
    14·1 answer
  • Identify the tips to create a well-designed digital portfolio.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!