I am asked to write a public method setText that takes a String parameter and changes the current text to this new
String. If no text existed before, this sets it. If there was text, this method will overwrite it. It doesn't return anything. And below is my code:
import java.util.Scanner;
public class WordProcessor
{
private String word;
private Scanner input;
public WordProcessor()
{
word = "";
input = new Scanner(word);
}
public WordProcessor(String inputString)
{
word = inputString;
input = new Scanner(word);
}
public void setText(String set)
{
word = set;
input = new Scanner(set);
}
But if use this method, whenever I try to use the hasNext method to get words on the string, it wont work.. how am I suppose to fix this? Iam confused, thanks
2006-10-27
14:00:46
·
2 answers
·
asked by
?
1