1answer.
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]
3 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]3 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
Which best describes TPM?
rodikova [14]

Answer:

Encryption used on hard drives

Explanation:

TPM is a hardware chip. It is a type of module that is used to authenticate the hardware devices with the help of encryption keys (passwords). It is the short form of Trusted Platform module. The hardware devices that be authenticated through this module may include personnel computer or laptops. There are different keys, password and security codes.

So, the best sentence that describes, TPM is Encryption built into hardware .

4 0
3 years ago
Jefffffffffffffffffffffffffcfffryyyryrryryyyyyyyyyyyyyyynhghgnc nb hc
kati45 [8]

Answer:

huh?

Explanation:

5 0
3 years ago
Read 2 more answers
The best technique to read​
Readme [11.4K]

Answer:

The best reading techniques are the SQ3R technique, skimming, scanning, active reading, detailed reading, and structure-proposition-evaluation.

Explanation:

6 0
3 years ago
Explain briefly about two online reservation system
Rus_ich [418]

Answer:

An Online Reservation System is a software you can use for managing reservations for your service. ... Basically, an online reservation system allows a potential customer to book and pay for a service directly through a website.

Explanation:

An Online Reservation System is a software you can use for managing reservations for your service. Be it a pool, fitness center, gym, yoga studio, or a parks & recreation center an Online Reservation System allows all kinds of service businesses to accept bookings and appointments online and manage their phone and in-person bookings with ease.

Basically, an online reservation system allows a potential customer to book and pay for a service directly through a website. That means from the moment a customer decides they want to book a slot for your service (be it an in-house class or online appointment) to choosing a date, picking a time, and paying for the booking, membership management, everything is handled online! It greatly reduces the workload on your staff and removes the opportunity for double-bookings.

hope it helps

3 0
3 years ago
Read 2 more answers
java methods Write a program whose input is a character and a string, and whose output indicates the number of times the charact
AfilCa [17]

Answer:

Here is the JAVA program:

import java.util.Scanner; // for taking input from user

//class to count number of times a character appears in the string

public class CharacterCounter

//method which returns number of times a character appear in string

{ public static int CountCharacter(String userString, char character)

   {  

       int counter = 0;   //stores the no of times character appears in string

for (int i=0; i<userString.length(); i++) //loop moves through entire string

       { // if character matches the character in the string

           if (userString.charAt(i) == character)

           counter++;  // adds one to the character counter variable

       }  

       return counter;     } // returns no of time character is found in string

public static void main(String[] args) {

    Scanner scanner = new Scanner(System. in);//takes input from user

    String string;

    char character;

       System.out.println("Enter a string"); //prompts user to enter a string

       string = scanner.nextLine(); //scans the input string

       System.out.println("Enter a character");

       // prompts user to enter character

       character = scanner.next().charAt(0); //scans and reads the character

       System.out.println("number of times character "+character + " appears in the string " + string +": " + CountCharacter(string, character));  }  }

// calls CountCharacter method to output no of times a character appears in the input string

Explanation:

The method CountCharacter() has a loop in which the variable i works as an index which moves through each character of the string and if the character of the string in i matches the character which is to be found in the string then the value of counter variable increments by 1. This means that counter variable keeps counting the number of time the character appears in the string. The loop breaks when value of i exceeds the length of the string which means that the i reaches the end of the string and has searched the entire string for the specified character. In the end the count variable returns the number of time character appeared in the string. The main() function takes as input from the user, a string and a character to be searched for in the string. It then calls CountCharacter() function to find the number of times that input character appears in the input string and displays it on the output screen.

The program along with its output is attached as a screenshot.

5 0
4 years ago
Other questions:
  • Jessica has pinned her favorite applications as icons on her desktop. She always clicks on these icons to work on them. Which us
    10·1 answer
  • On the home ribbon, what do you use to change the font size of characters in a cell
    9·1 answer
  • Which spreadsheet operation does a look function perform?
    5·1 answer
  • What kind of document serves as a legally binding contract or part of a contract that defines, in plain language and in measurab
    14·1 answer
  • What are face shields intended to protect you from? (select best answer?
    8·2 answers
  • On an unweighted scale, a grade of A is worth _____ points
    7·1 answer
  • Which of the following entries into the username and password fields will NOT cause us to gain admin access? You may assume that
    12·1 answer
  • Difference between primary key and foreign key
    12·1 answer
  • Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    12·1 answer
  • Why do we buy new asset​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!