Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need to complete all //TO DO comments in the following class (java code): public class Trove implements Treasure { // TODO instance variables with documentation
Need to complete all //TO DO comments in the following class (java code):
public class Trove implements Treasure { // TODO instance variables with documentation comments /** * Constructs a new Trove with the Treasure objects specified by * contents. * * @param contents * The Treasures to store in this Trove. Must not be null * nor contain null. The caller of the constructor is allowed * to make changes to the parameter array after the constructor * call, and this Trove object (and its internal representation) * will not be affected by this. */ public Trove(Treasure[] contents) { // TODO } /** * Returns the sum of the values of the component Treasures. * * @return the sum of the values of the component Treasures */ @Override public long getValue() { return 0; // TODO } @Override public String toString() { return null; // TODO } }
The implemented class:
public interface Treasure { /** * Returns the value of the Treasure. Note that the value of a Treasure * can be positive, zero, or negative. * * @return the value of the Treasure */ long getValue(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started