Question: I need to complete //TO DO comment in this java class: ValueVisitor.java import Treasure; /** * Visitor keeping a running total of the values of
I need to complete //TO DO comment in this java class:
ValueVisitor.java
import Treasure; /** * Visitor keeping a running total of the values of all Treasure objects * passed to the visit method. */ public class ValueVisitor implements Visitor { // TODO instance variables and documentation comments, // perhaps also public 0-argument constructor @Override public Treasure visit(Treasure t) { return null; // TODO } /** * Returns the total value of all Treasure objects that have been arguments * to the visit method. * * @return the total value of all Treasure objects that have been arguments * to the visit method */ public long getValue() { return 0; // TODO } } Other related classes:
Visitor.java
public interface Visitor { /** * Performs a visit on a Treasure object, possibly calling its methods. * Returns the replacement Treasure for t (or t itself) to be stored in * the visited data structure * * @param t * The Treasure to visit. Must not be null. * @return the replacement Treasure for t (or t itself) to be stored in * the visited data structure */ Treasure visit(Treasure t); /** * Returns whether this Visitor wants to visit more Chambers. * The default implementation always returns true. * * @return whether this Visitor wants to visit more Chambers */ default boolean wantsMoreVisits() { return true; } } 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(); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
