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
Ghella [55]
3 years ago
6

You need to write a class called SingleItemBox (in a file called SingleItemBox.java that you create). This class has a construct

or that takes a single item (of any type) and puts it in the box. You also need a method called getItem() which provides the item back to the user but does not remove it from the box (this is an "accessor", if you remember, sometimes called a "getter"). Make sure to comment your code as you go in proper JavaDoc style. Please implement this code using generics concept in java.
Computers and Technology
1 answer:
fgiga [73]3 years ago
7 0

Answer:

class SingleItemBox<ItemType> {

 

  ItemType box;

  SingleItemBox(ItemType item) {

      this.box = item;

  }

  public ItemType getitem() {

      return this.box;

  }

}

public class Main {

  public static void main(String[] args) {

      SingleItemBox <Integer> intObj = new SingleItemBox(10);

      System.out.println(intObj.getitem());

     

      SingleItemBox <String> sObj = new SingleItemBox("banana");

     

      System.out.println(sObj.getitem());

  }

}

Explanation:

  • Inside the singleItemBox, create a variable box of type itemType.  
  • Create a constructor of this class and pass this item as a parameter.
  • Create the getItem method that returns this Box.  

  • Inside the main function create an object of singleItemBox class.  
  • Display the box by calling the getter method.
  • Create an object of singleItemBox class of type string and call the getter method.
You might be interested in
Identify the publisher in this citation:Carter,Alan.A guide to Entrepreneurship.New York: River’2008.Print.
Ilya [14]

Answer:

River

Explanation:

Citation is always needed when we quote some contents from other sources such as book. Citation follows a specific format. The given citation follows the format <em>Last Name, Fisrt Initial. Book Title. Publisher City: Publisher Name' Year of Publication.Print.</em>

So, the River is the publisher name from the given citation format. The publisher name is preceded by the publisher city.

5 0
4 years ago
The blank areas around the outside edges of a document are called the _____. a. settings b. margins c. blank space d. empty spac
nevsk [136]

I think it will be B margins

7 0
3 years ago
What should we do to protect data
puteri [66]
Six Easy Steps You Can Take To Protect Your Data Online
Protect Passwords. Lock your phone with a strong password and fingerprint or Touch ID. ...
Turn off Lock Screen Notifications. ...
Lock Your Apps. ...
Hide Your Photos. ...
Use A Private Number. ...
Keep Your Browsing Secret.
3 0
3 years ago
The merge process involves which two types of files?
Natasha2012 [34]


On Microsoft Word a merge process involves the primary and secondary files. The correct choice is the letter

C. Primary and secondary
<span>
I hope it helps, Regards.</span>
3 0
4 years ago
Suppose you have a stack ADT (i.e., an Abstract Data Type that includes operations to maintain a stack. Design a flowchart or su
Whitepunk [10]

Answer:

One approach would be to move all items from stack1 to stack2 (effectively reversing the items), then pop the top item from stack2 and then put them back.

Assume you use stack1 for enqueueing. So enqueue(x) = stack1.push(x).

Dequeueing would be:

- For all items in stack1: pop them from stack1 and push them in stack 2.

- Pop one item from stack2, which will be your dequeue result

- For all items in stack2: pop them from stack2 and push them in stack 1.

Hope it makes sense. I'm sure you can draw a diagram.

5 0
3 years ago
Other questions:
  • Public static Object[] question4(Student student1, Student student2)
    15·1 answer
  • Sabiendo que el engranaje motriz tiene 14 dientes y gira a 4000 RPM, y el conducido tiene 56 dientes, responde:
    11·1 answer
  • In what order does the air flow in a canister vacuum cleaner pass through the following components?
    11·1 answer
  • A. What sectors are used with Foo?
    8·1 answer
  • ____ is an approach to boundary spanning which results from using sophisticated software to search through large amounts of inte
    5·1 answer
  • I just wanna promote my 2 yt channels c: <br> (the channels are in the comments of this question)
    14·1 answer
  • The mutating-table error is raised when a trigger attempts to execute a. an INSERT, UPDATE, or DELETE while another user is upda
    10·1 answer
  • Which of the following are TRUE? A function can call another function. As long as the function is defined anywhere in your progr
    14·1 answer
  • We cannot share software in computer network true or false​
    9·1 answer
  • Need answer ASAP
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!