• Home
  • Blog
  • Java Data structure assignment(Generics and Unordered Lists)

Java Data structure assignment(Generics and Unordered Lists)

0 comments

Pls read the attached description file.

In this exercise you will use multiple generics to develop a StorageBin class. The StorageBin class will

store a generic item and a generic unique identifier for that item. For example, the StorageBin may store

hardware tools and a unique ID for each tool.

You are provided with the following starter code files: StorageBinTester.java, StorageBin.java, Tool.java

Create or complete the following classes:

The StorageBin.java class should have the following methods and functionality:

• Two generic ArrayLists to store generic items

• A constructor to set up the ArrayLists

• sizeofBin():int method which returns the number of items stored

• addItem(T item, U id):void method which adds an item and its unique ID to the arrays.

o This method prints an error if an item is added with an already existing ID

• removeItem(U id): T method remove the item with the given ID from the bin and returns it to the

caller.

• displayItems(): void method prints the contents of the storage bin in the format Name, function,

and ID (see test cases below)

Create a Tool.java class with the following properties:

• String to store the name of the tool

• Tool(String name) constructor to set up the name of the tool

• getName():String method to return the name

• toString(): String method which returns the name of the tool.

Create a Hammer.java, Saw.java, and Level.java class by extending the Tool class. Each class should

have the following properties:

• A String to store the function of the tool

• Hammer(String name): constructor to set the name by calling super()

• setFunction(String function):void method to set the function of the tool

o Hammer function: “I hammer stuff”

o Saw function: “I saw stuff”

o Level function: “I make sure everything is even”

• toString():String override the parent’s toString() method to return the tool’s name + function

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}