public class ScaleBranch extends SoundBranch { /** * Amount to scale **/ double factor; /** * Construct a branch with this factor **/ public ScaleBranch(double nufactor){ super(); // Call superclass constructor this.factor = nufactor; } /** * Accessors **/ public double getFactor() {return this.factor;} public void setFactor(double nufactor) {this.factor = nufactor;} /** * Method to return a string with informaiton * about this branch */ public String toString() { return "ScaleBranch ("+factor+") "+super.toString(); } /** * Collect all the sound from our children, * then collect from next. * Scale the children * @param pen Turtle to draw with **/ public Sound collect(){ Sound childSound; if (children != null) {childSound = children.collect().scale(factor);} else {childSound = new Sound(1);} // Collect from my next if (this.getNext() != null) {Sound nextSound=this.getNext().collect(); childSound = childSound.append(nextSound);} return childSound; } /** * Collect all the sound from our children, * then collect from next. * Scale the next list, not the children * @param pen Turtle to draw with **/ public Sound collectAfter(){ Sound childSound; if (children != null) {childSound = children.collect();} else {childSound = new Sound(1);} // Collect from my next if (this.getNext() != null) {Sound nextSound=this.getNext().collect(); childSound = childSound.append(nextSound.scale(factor));} return childSound; }}