Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help to complete //TO DO comments in the following java classes: Trove.java public class Trove implements Treasure { // TODO instance variables with documentation
Please help to complete //TO DO comments in the following java classes:
Trove.java
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 } }
FancyTrove.java
import HasName; /** * A FancyTrove is a Trove that has a name. Much of the value of a FancyTrove * comes from its name (it is presumably a famous treasure box). Thus, the * value of a FancyTrove is the sum of the values of the component Treasures * plus a specific factor (currently 100) multiplied by the number of * characters of the FancyTrove's name. */ public class FancyTrove extends Trove implements HasName { // TODO instance variables with documentation comments /** Internal constant used for determining the value of a FancyTrove. */ private static final long VALUE_FACTOR = 100L; /** * Constructs a new Trove with the Treasure objects specified by * contents. * * @param contents * The Treasures to store in this FancyTrove. 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 FancyTrove object (and its internal * representation) will not be affected by this. * @param name * The name of the FancyTrove. Must not be null. */ public FancyTrove(Treasure[] contents, String name) { super(contents); // TODO } @Override public String getName() { return null; // TODO } @Override public String toString() { return null; // TODO } }
Other dependent classes:
Treasure.java
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(); }
HasName.java
public interface HasName { /** * Returns the name associated with the object. * * @return the name associated with the object */ String getName(); }
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