toString() is a method inherited by all classes you create in Java. The default implementation give you the type of the class followed by a @ followed by a hex address. You can override the toString method in any class you create to return a String which will gives useful information regarding the instance that calls it.
It sounds like the toString method is already implemented in the Sequence class to return a String representation of the instance. So getting the String is straight forward: All you need to do is call toString on the instance.
To verify what you're getting from the toString method, simply insert a println...
System.out.println("The String is: " + dna1.toString());
But it sounds like your task is really to provide the input/output code that writes this String to the indicated file. Is this right? If so, what code do you have so far?
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Dec 21, 2005
Thanks for the replies
Gary, you are correct when you say
"But it sounds like your task is really to provide the input/output code that writes this String to the indicated file."
The code for my toString method within my Sequence class gets a copy of the description and content of the sequence object.
I have tried your suggestion
The printed line is The String is: the DNA description is >DNA1 the DNA content is ATGCAAGGCCATC
I think what I need to be able to do is to write which ever Sequence object is the current one to a file. I can set the name of the file to something like output.txt So I think I need to use
and pass it to a filewriter to allow the content of toString to be written to a file. Does this make sense or am I missing something?