Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello there, Can anyone give me general idea on how generics work in java please? And Modify the Box class from the following code and

Hello there, Can anyone give me general idea on how generics work in java please? And Modify the Box class from the following code and Add an ArrayList to keep track of the "box history"- all items that have been previously added to the box. Mention the new instance data variable, modified constructor, and the modified replace Contents method.

public class Box { private T thing; private int thingCount; public Box(T firstThing) { this.thing = firstThing; this.thingCount = 1; } public T getContents() { return thing; } public int getCount() { return thingCount; } public void replaceContents(T newThing) { this.thing = newThing; thingCount++; } @Override public String toString() { return thing.toString() + " (item " + thingCount + ")"; } @Override public boolean equals(Object other) { if(other instanceof Box) { Box otherBoxR = (Box) other; boolean sameThing = this.thing.equals(otherBoxR.thing); boolean sameCount = this.thingCount==otherBoxR.thingCount; return sameThing && sameCount; } else { return false; } }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Domain Transfer Learning With 3q Data Processing

Authors: Ahmed Atif Hussain

1st Edition

B0CQS1NSHF, 979-8869061805

More Books

Students also viewed these Databases questions