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]
1 year 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]1 year 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
Arrays are described as immutable because they are two dimensional. are arranged sequentially. can be reordered. cannot be chang
Vlada [557]

Answer:

Arrays are described as immutable because they cannot be changed once they are defined.  (D on Edge)

Explanation:

It's in the notes and I just took the test (2020)

6 0
2 years ago
How did josh norman and mike keller provide coverage of katrina?
Digiron [165]
<span>They wrote live updates to a blog, so D. The blog was called "Eye of the Storm." It was written as a series of personal musings and photographs of places where the storm hit- first hand accounts of the disaster. They received a journalism award for it.</span>
6 0
2 years ago
Read 2 more answers
Someone claims that the big O notation does not make sense at all, and they give the following example. An algorithm A that proc
Svetllana [295]

Answer:

Big Oh notation is used to asymptotically bound the growth of running time above and below the constant factor.

Big Oh notation is used to describe time complexity, execution time of an algorithm.

Big Oh describes the worst case to describe time complexity.

For the equation; T(N) = 10000*N + 0.00001*N^3.

To calculate first of all discard all th constants.

And therefore; worst case is the O(N^3).

7 0
2 years ago
Which of the following is a collection of unprocessed items, which can include text, numbers, images, audio, and video?A. DataB.
Tema [17]

Answer:

Option A is the correct answer for the above question.

Explanation:

Data can be defined as raw fact which can be useful when it will be processed. The processed data can be formed as information. The data can be anything. It can b e text or audio or images or video. The above question asked about the term which is an unprocessed item and can form information after processing. Then the answer is Data which stated from the option A. So Option A is the correct answer while the other is not because--

  • Option B states about instruction which is useful to process the data.
  • Option C states about Programs that can be formed when one or more instruction is grouped.
  • Option D states about the information that the user can get after processed the data.

6 0
2 years ago
In one to three sentences describe one reason you would import data into a datebase
Bond [772]

The primary reason that you would import data into a database is because the data already exists somewhere else.

As an example, you may have a spreadsheet that contains names and telephone numbers of a group of people. It is much faster to import this data into a database instead of manually entering the information.

8 0
2 years ago
Other questions:
  • The tuna marketers' task in the "tunathewonderfish.com" website and related campaign was to ________.
    15·1 answer
  • Which port, along with a special card and cables, supports the connection of microcomputers, modems, and printers in a local are
    6·1 answer
  • ____ is a program placed on a computer without the user's knowledge that secretly collects information about the user
    14·1 answer
  • The final step of the DHCP Discovery process is known as ______.
    5·1 answer
  • Which item is essential to know before sketching a navigation menu flowchart? template specifics, such as horizontal or vertical
    12·1 answer
  • A U.S. social security number consists of a string of 9 digits, such as "444422333". Assume that input consists of a sequence of
    6·2 answers
  • Which two factors most influenced the growth of the Internet during the 1970s?
    7·2 answers
  • #Write a function called fancy_find. fancy_find should have #two parameters: search_within and search_for. # #fancy_find should
    9·1 answer
  • Through which of the devices listed are we able to connect to wireless networks? Check all that apply.
    14·1 answer
  • Plz help code practice for python
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!