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
In an IPv4 datagram, the fragflag bit is 0, the value of HLEN is 5 (Its unit is word or 32-bits ), the value of total length is
Karolina [17]

Answer:

i aint sure

Explanation:

3 0
2 years ago
The hostel in which you plan to spend the night tonight offers very interesting rates, as long as you do not arrive too late. Ho
faust18 [17]

Answer:

Answered below

Explanation:

// Python implementation

incrementAmount = 5

basePrice = 10

price = 0

arrivalHour = int(input("Enter arrival hour 0-12: ")

if arrivalHour < 0 or arrivalHour > 12:

print ("Invalid hour")

if arrivalHour == 0:

price = basePrice

else:

price = arrivalHour * incrementAmount

totalPrice = price + basePrice

if totalPrice > 53:

totalPrice = 53

print ("Your bill is $totalPrice")

4 0
2 years ago
George is working with an image in Photoshop. He added a lot of effects to the image. He saved the first draft of the file. The
Alja [10]

Answer:

JPEG, PDF

Explanation:

3 0
2 years ago
Read 2 more answers
What is the impact of VR on Educational Learning rather than games?​
nekit [7.7K]

Answer : Candice

Explanation: Candice penis fit in your mouth

3 0
2 years ago
A hidden backlog contains the projects that the IT department is not aware of because of low feasibility.
Finger [1]

Answer: True

Explanation:

Yes, the given statement is true that the due to the very low feasibility the IT (Information technology) department are not aware of the hidden backlog that basically contain projects.

The feasibility is the main factor in the IT department as it helps to study whole objective of the project and then also uncover all the strength and weakness of the project so that we can easily go through the details to make the project more efficient and reliable.

8 0
2 years ago
Other questions:
  • Explain briefly why the crowd sourcing technique could help a single individual with a difficult personal decision.
    14·1 answer
  • 5.William travels a lot on business purpose. He needs to regularly communicate with his business partner. He also needs to send
    15·1 answer
  • Our company is only interested in purchasing a software upgrade if it leads to faster connectivity and data sharing. The old sof
    7·1 answer
  • A client is asking for a printing solution that will print three sheets of paper with identical information on each page with a
    13·1 answer
  • Print "userNum1 is negative." if userNum1 is less than O. End with newline Convert userNum2 to 0 if userNum2 is greater than 8.
    10·1 answer
  • Modify the sentence-generator program of Case Study so that it inputs its vocabulary from a set of text files at startup. The fi
    15·1 answer
  • The new Director of Information Technology has asked you to recommend a strategy to upgrade the servers on their network. Recomm
    9·1 answer
  • Write a cout statement that prints the value of a conditional expression. The conditional expression should determine whether th
    6·1 answer
  • Which of the following is not a characteristic of a good value log entry
    15·1 answer
  • 1.erros can easily be ____ 2.work is done in an ____ no mess environment 3.colors do not _____ and brushes are never ______ 4.st
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!