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
Ghella [55]
2 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]2 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
The ______________________ are incident management personnel that the incident commander or unified command assign to directly s
postnew [5]

Answer:

The Command Staff are the incident management personnel that the incident commander or unified command assign to directly support the command function.

Explanation:

Based on the information retrieved from the ICS (Incident Command System), to handle properly incidents that occur, Command Staff are assigned by the incident commander or unified command.

8 0
2 years ago
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
Vika [28.1K]

int firstNumber,secondNumber = -1, duplicates = 0;

do {

cin >> firstNumber;

if ( secondNumber == -1) {

secondNumber = firstNumber;

}else {

if ( secondNumber == firstNumber )

duplicates++;

else

secondNumber = firstNumber;

}

} while(firstNumber > 0 );

cout << duplicates;

7 0
2 years ago
Your license can be canceled if you __________
Gemiola [76]
Your license can be canceled if you do not have proof of insurance or if you have unpaid tickets or fines. Your license can also be canceled if you are behind in child support payments in Florida.
6 0
2 years ago
Read 2 more answers
What is wrong with line 1?
Gelneren [198K]

Answer:

The set is a object of the class 'H' and the setY method is a member of G class which is not called by the object of H class.

Explanation:

  • If a user calls the G function which is not a private by the help of H class objects then it can be called. It is because all the public and protected methods of A class can be accessed by the B class if B extends the A-class.
  • If any class is extended by the other class then the derived class holds the property of the base class and the public and protected method can be accessed by the help of a derived class object.
  • The derived class object can be created by the help of base class like written in the "line 1".
  • But the base class can not call the member of the derived class.
5 0
2 years ago
When pasting an object which has been copied from a different slide, where on the slide does the object paste, assuming nothing
k0ka [10]
In the middle of the slide
3 0
2 years ago
Other questions:
  • Danilo is planning the art to include in a business proposal his team is preparing. For which of the following items should Dani
    7·2 answers
  • The main problem with radio transmission is which of the following? Select one: a. Radio waves cannot travel through walls. b. W
    9·2 answers
  • In which job role would a course in 3D modeling help with professional career prospects?
    11·1 answer
  • Database management systems are expected to handle binary relationships but not unary and ternary relationships.'
    7·1 answer
  • Write a program that first reads in the name of an input file, followed by two strings representing the lower and upper bounds o
    8·1 answer
  • Frequent menu users can become annoyed if they must make several menu selections to complete a simple task. Suggest two ways you
    10·1 answer
  • Use Excel to develop a regression model for the Consumer Food Database (using the "Excel Databases.xls" file on Blackboard) to p
    13·1 answer
  • Consider the following class definitions.
    10·1 answer
  • Distinguish among packet filtering firewalls, stateful inspection firewalls, and proxy firewalls. A thorough answer will require
    9·1 answer
  • [20 points] 3.3 Code Practice: Question 2
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!