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
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A
harina [27]

Answer:

se explaination

Explanation:

//Design a class named Person

public class Person

{

//A person has a name, address, phone number, and email address.

String name;

String address;

String phone;

String email;

//Constructor with arguments

public Person(String pname,String paddress,String phNum,String pemail)

{

name=pname;

address=paddress;

phone=phNum;

email=pemail;

}

// toString() method to return the name

public String toString()

{

return getClass().getName()+" "+name;

}

}

---------------------------------------------------------

//Student.java

public class Student extends Person

{

//A student has a class status

//(freshman,sophomore, junior, or senior).

//Define the status as a constant.

final int freshman =1;

final int sophomore =2;

final int junior=3;

final int senior=4;

String status="freshman";

//Constructor with arguments

public Student(String name, String address,String phonenumber, String email, int Status)

{

super(name,address,phonenumber,email);

if(Status == 1)

{

status = "freshman";

}

if(Status == 2)

{

status = "sophomore";

}

if(Status == 3)

{

status = "junior";

}

if(Status == 4)

{

status = "Senior";

}

status = "Student";

}

public String toString()

{

return super.toString() + " " + status;

}

}

------------------------------------------------------

//Employee.java

public class Employee extends Person

{

//An employee has an office, salary, and date hired.

String office;

double salary;

java.util.Date dateHired;

//Constructor with arguments

public Employee(String name,String address,String phonenumber,String email,String off,double sal)

{

super(name,address,phonenumber,email);

office=off;

salary=sal;

}

public String toString()

{

return (super.toString() + " " + office +" " + salary);

}

}

--------------------------------------------------------

//Faculty.java

public class Faculty extends Employee

{

//A faculty member has office hours and a rank.

String officeHours;

String rank;

//Constructor with arguments

public Faculty(String name,String address,String phonenumber,String email,String off,int salary,String offHours,String ranks)

{

super(name,address,phonenumber,email,off,salary);

officeHours=offHours;

rank=ranks;

}

public String toString()

{

return (super.toString() + " " + officeHours +" " + rank);

}

}

-----------------------------------------------------------------------------

//Staff.java

public class Staff extends Employee

{

//A staff member has a title

String title;

//Constructor with arguments

public Staff(String name,String address,String phonenumber,String email,String off,int salary,String ti t)

{

super(name,address,phonenumber,email,off,salary);

title=ti t;

}

public String toString()

{

return (super.toString() + " " + title);

}

}

3 0
2 years ago
Splunk In most production environments, _______ will be used as the source of data input?
Wittaler [7]

Answer: Forwarders

Explanation:

Splunk is defined as the software technology which helps in organization of applications, examining and monitoring of the data and information analytics.It performs the operation of indexing, processing and gathering to produce graphs, alert ,report etc .

  • Forwarders are the component of Splunk software that gathers the information and transmit it to the Splunk clod for further analysis and processing .It is considered as the reliable method for input of data.

6 0
2 years ago
enter a formula in cell b10 to return a value of 35000 if the net profit after tax (cell B() is greater than or equal to 350000
Aliun [14]

Step by step explanation:

Statement to be written in cell B10 :

IF ( B9 >= 350000 , 35000, 1000)

Formula:

IF ( logical_test ,  [value_if_true] ,  [value_if_false] )

logical_test = Net Profit After Tax (cell B9)

value_if_true = 35000

(if the Net Profit After Tax (cell B9) is greater than or equal to 350000)

    value_if_false = 1000

(if the Net Profit After Tax (cell B9) is lesser than 350000)


6 0
2 years ago
Read 2 more answers
One factor affecting digital camera quality is the number of pixels, measured in ____, used to store the data for each image.
Vlada [557]
One factor affecting digital camera quality is the number of pixels, measured in megapixels, use to store the data for each image.
5 0
2 years ago
Read 2 more answers
Universal Containers has implemented a strict software architecture for their custom Apex code. One of the requirements is that
maxonik [38]

Answer:

The required coding for the architect to meet these requirement has been described below.

Explanation:

The following ways will help the architecture to meet the requirement.

Create a reusable SOQLQueries class; specify “With Sharing” on the methods that require user context and “Without Sharing” on the methods requiring system context.

Create a SystemSOQLQueries class and a UserSOQLQueries class; set the “With Sharing” keyword on the UserSOQLQueries class and “Without Sharing” on the SystemSOQLQueries class.

6 0
2 years ago
Other questions:
  • What helps companies and organizations to target masses of people, provide 24/7 services, and deliver better marketing in a chea
    13·2 answers
  • Which element of the word program window contains buttons for saving a document and for undoing, redoing, and repeating a change
    5·1 answer
  • Blender questions
    8·2 answers
  • You are attempting to open a file containing a list of integer numbers, each on a separate line, and read them into Python as in
    6·1 answer
  • Consider a DASH system for which there are N video versions (at N different rates and qualities) and N audio versions (at N diff
    8·1 answer
  • Consider the following relation:CAR_SALE(Car#, Date_sold, Salesperson#, Commission%, Discount_amt)Assume that a car may be sold
    12·1 answer
  • As part of the duties of a digital forensics examiner, creating an investigation plan is a standard practice. Write a 3 to 4 (no
    9·1 answer
  • Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two
    12·1 answer
  • Assume that k corresponds to register $s0, n corresponds to register $s2 and the base of the array v is in $s1. What is the MIPS
    10·1 answer
  • Write code that determines the number of full days represented by the number of hours stored in the variable hours and stores th
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!