Question: Part 1 : Make a box that can hold one item This first part checks that you know how to use generics, write JavaDocs, and

Part 1: Make a box that can hold one item
This first part checks that you know how to use generics, write JavaDocs, and use the basic command line tools youll use
throughout the semester. You need to write a generic class called SingleItemBox (in a file called
SingleItemBox.java that you create). It must have the following three features:
1. a constructor that takes a single item and puts it in the box.
2. 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).
3. a single-parameter method called setItem() which puts a new item into the box and returns the old item.
NOTES:
Make sure to comment your code as you go in proper JavaDoc style.
Item put in the box cannot be null you must check this and throw an IllegalArgumentException with error
message "Item cannot be null!" if null is used.
Dimitriadis/Zhong Project 0: Project Skills Check CS310- Spring 2024
3
To check that youve got the right idea, weve provided a class called BoxUsageDemo.java which creates boxes for
items of different classes. You should not alter this class to make it work, but rather alter your box to allow the provided
code to work and print our yays. You can use the command "java BoxUsageDemo" to run the testing code defined in
main(). You could also edit this main() to perform additional testing (we wont be using BoxUsageDemo for testing,
its just a demo for you).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!