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
Write an interface named HGTTU which specifies a universal constant int value of 42, and a single method named getNormilazedIntV
Nadusha1986 [10]

Answer:

Hope this helps.

//HGTTU.java

public interface HGTTU {

 int universalConstant = 42;

  public int getNormilazedIntValue();

}

//MyInt.java

public class MyInt implements HGTTU {

  int instanceFiled;

Override

  public int getNormilazedIntValue() {

      return instanceFiled+universalConstant;

  }

}

Explanation:

8 0
1 year ago
In 2007, this wireless security algorithm was rendered useless by capturing packets and discovering the passkey in a matter of s
Basile [38]

Answer:

The correct answer to the following question is option A. Wired Equivalent Privacy (WEP).

Explanation:

WEP (Wired Equivalent Privacy) is the security protocol which is specified in IEEE Wi-Fi (Wireless Fidelity) standard 802.11b, which is designed for providing a WLAN (Wireless Local Area Network) with the level of privacy and security.

Wardriving is act of searching for the WI-FI (Wireless Fidelity) networks by the person in the moving vehicle by using PDA (Personal Digital Assistant), smartphones or portable computer.

7 0
2 years ago
Read 2 more answers
List 5 kinds of acquaintances who told Debbie Fields would fail?<br><br> right answer only
Mamont248 [21]
<span><span>1.her husband’s business acquaintances2.Debbi’s mother3.her in-laws4.her friends 5.fellow students at Los Altos Junior College </span>At age 20, Debbi Fields always loved baking cookies and decided that she thought about starting a business. Her family and friends argued that the business would fail but Debbi managed to get a loan. <span>
</span></span>
3 0
2 years ago
Read 2 more answers
Rapunzel s-a născut într-un ţinut îndepărtat într-un regat necunoscut. Mama vitregă a închis-o pe Rapunzel într-un turn foarte î
andrey2020 [161]
Iche hebie zaft no guts dude
5 0
2 years ago
Keith has data in cell a14 and he would like the cell to be empty. keith should _____.
Elza [17]
Press CTRL + HOME and then press delete
7 0
2 years ago
Other questions:
  • python Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value i
    7·1 answer
  • Static packet filtering firewalls are limited to ________. inspecting packets for which there are good application proxy filteri
    8·1 answer
  • What is the value of x after each of the following statements is encountered in a computer program, if x=1 before the statement
    9·1 answer
  • Write a second constructor as indicated. Sample output: User1: Minutes: 0, Messages: 0 User2: Minutes: 1000, Messages: 5000
    15·1 answer
  • In a ____________________ attack, the attacker sends a large number of connection or information requests to disrupt a target fr
    14·1 answer
  • Write a program that calculates an adult's fat-burning heart rate, which is 70% of 220 minus the person's age. Complete fat_burn
    13·1 answer
  • Information systems cannot solve some business problems. Give three examples and explain why technology cannot help.
    11·1 answer
  • If the object instance is created in a user program, then the object instance can access both the public and private members of
    9·1 answer
  • Generating a signature with RSA alone on a long message would be too slow (presumably using cipher block chaining). Suppose we c
    10·1 answer
  • Which is the correct notation to specify the following inheritance?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!