201k views
4 votes
You need to write a class called SingleItemBox (in a file called SingleItemBox.java that you create). This class has a constructor 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.

User Locksley
by
6.2k points

1 Answer

3 votes

Answer:

public class SingleItemBox { // class definition

SingleItemBox( Point [] item){

box = item; // the constructor method is initiallized with a box variable

}

static getItem( ) {

return this.box // the getter method to return the box item

}

}

Step-by-step explanation:

The java class SingleItemBox is defined as well as its constructor and a getter method.

User Gayan Charith
by
7.3k points