I\'m just missing the toString method, could someone help me please.This is what
ID: 3616996 • Letter: I
Question
I'm just missing the toString method, could someone help me please.This is what toString needs to do:The toString() method should print out information about the linkedlist beginning at the
current node including the number of nodes (from the currentposition to the end of the list).
import jm.music.data.*;
import jm.JMC;
import jm.util.*;
import jm.music.tools.*;
/**
* Represents a node in a flexible song structure
* @author Noman Arain
*/
public class SoloNode
{
/** the next SoloNode in the list */
private SoloNode next;
/** Note containing myNote */
private Note myNote;
/**
* Construct a new song node.
* The next part is empty, and ours is a
* blank new part.
*/
public SoloNode()
{
this.next = null;
this.myNote = null;
}
/**
* myNote takes a note and makes it the one for
* this node
* @param myNote the note for this node
*/
public SoloNode(Note myNote)
{
this.myNote = myNote;
}
/**
* Creates a link between the current node and the
* input node
* @param nextOne the node to link to
*/
public void setNote(Note myNote)
{
this.myNote = myNote;
}
/**
* Creates a link between the current node and the
* input node
* @param nextOne the node to link to
*/
public void setNext(SoloNode next)
{
this.next = next;
}
/**
* Get the next song node
* @return the next song node or null if none
*/
public Note getNote()
{
return this.myNote;
}
/**
* Get the next song node
* @return the next song node or null if none
*/
public SoloNode getNext()
{
return this.next;
}
public Phrase collect()
{
Phrase collector = new Phrase();
SoloNode current = this;
while (current != null)
{
collector.addNote(current.getNote());
// Now, move on to the nextelement
current = current.getNext();
}
return collector;
}
public String toString()
{
//Note n1 = new Note(myNote);
return "";
}
}
Explanation / Answer
Are you going to pass in a parameter? you said that it shouldprint from the current node. Does that mean you want to print fromnode 2 or from the node that has myNote="something"? I might just be tired, but it doesn't look like you keep trackof the first node and this could be where you are getting stuck.Basically you could create a null node. Such as firstNode = newSoloNode() <--- which would be a null node. then you would add aspecial case to check if its the first Node or not whenadding something like if firstNode.next = null then firstNode.next = (some NewNode) else current.next = (some New Node) and update current. (orlast Node) you could also keep track of the number of Nodes you add justby creating a variable. Anytime you add a new Node then incrementthat variable. If you have a delete function then you wouldsubtract. (n++; or n--;)Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.