public LString toUppercase(){
Node current = front;
while(current != null){
current.data = Character.toUpperCase(current.data);
current = current.next;
}
return front;
}
front
is of type Node
, but the signature of the method is public LString toUppercase()
, which means that it is expected to return an LString
instance.
Think about what it is that you actually want to return. You want to return an LString
that contains uppercase characters, right? But that is already the instance that you are working with! So you can either return this
:
public LString toUppercase(){
Node current = front;
while(current != null){
current.data = Character.toUpperCase(current.data);
current = current.next;
}
return this;
}
But in this case you will still need another method that prints out the uppercase characters:
LString lString = new LString();
...
...
lString.toUppercase(); //lString is already modified and contains uppercase characters! You
//don't have to "return" anything. If you returned "this" this
//line would be lString = lString.toUppercase(), but that's
//not buying you anything special.
System.out.println(lString.toString()); //Assuming you have a toString method
//that prints out the characters.
By calling the toUppercase
instance method you have already modified your LString
instance so there is really no need to return anything.