Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help to complete //TO DO comments in the following three java classes: 1. SizeVisitor.java import Treasure; /** * Counts how many times the visit
Please help to complete //TO DO comments in the following three java classes:
1. SizeVisitor.java
import Treasure; /** * Counts how many times the visit method has been called. Useful for * determining the number of entries in a container data structure. */ public class SizeVisitor 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 size of the visited data structure according to the * number of times the visit method has been called. * * @return the size of the visited data structure according to the * number of times the visit method has been called. */ public int getSize() { return 0; // TODO } }
2. 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 } }
3. TreasureSeeker.java
import HasName; import Treasure; /** * A TreasureSeeker is an adventurous person with a name who collects treasures * of positive value as long as a specified desired value has not been reached. * Leaves a mysterious note whenever they take a treasure in a visit. Implemented * as a Visitor to ensure independence from the concrete data structure(s) in * which the Treasures can be found. */ public class TreasureSeeker implements Visitor, HasName { // TODO instance variables and documentation comments /** * Constructs a new TreasureSeeker object with specified name and * desiredValue. * * @param name * The name of the TreasureSeeker. Must not be null. * @param desiredValue * The value that this TreasureSeeker currently still desires. */ public TreasureSeeker(String name, long desiredValue) { // TODO } @Override public Treasure visit(Treasure t) { return null; // TODO } @Override public String getName() { return null; // TODO } /** * Returns the value that this TreasureSeeker currently desires. * * @return the value that this TreasureSeeker currently desires */ public long getDesiredValue() { return 0; // TODO } @Override public String toString() { return null; // TODO } }
Other dependent 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(); }
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