aspose file tools*
The moose likes Beginning Java and the fly likes validLetters() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "validLetters() " Watch "validLetters() " New topic


sara salem

Joined: Jun 20, 2006
Posts: 3
Hi every one,
I have an abstract class and its constructer must take two String as instance varable (content,description) and it contain two method the first one is an abstract method called validLetters() this method will be implement in two subclass and it must returns a certain letters such as ("A","T","C","G")in a set (collection) of DNA subclass.
The second method is validate() this method must called by constructer of superclass and it goes through the content string and checks that each letter is valid. If it finds one that isn't it creates an Exception with the content and the duff letter index, and throws it. In order to deal with different sequences having different valid letters we declare an abstract method validLetters() which returns the relevant letters as to be checked in validate().
I try to understand how can I use validLetters() in side the validate()
and I try this :
public abstract char[] validLetters();
public void validate() throws InvalidSequenceException
char[] letters = letters .getContent();
for(int i=0;i < letters.length;i++)
if (letters[i]==validLetters() )
{ system.out.println("sequence is in fasta");
else throw(new InvalidSequenceException());
I think this method full of mistaks
and how can I call validate by constructer is it correct to w
private String description , content ;
public Sequence (String description ,String content)
{ // instructor
this.description = description;
this.content = content;
thanks alot
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 39436
Welcome to the Ranch, Sara.

I am afraid I don't think your app will work. You cannot return several things from a method, only one, so you can't use "letters[i]==validLetters()."

What you might do, is something like this:-
You will have to do something about catching the exception. Thre are lots of possibilities. And you probably wouldn't want to call the validateLetters() method from the constructor.

You do realise of course, your method as shown won't work for more than 2147483648 base-pairs?

sara salem

Joined: Jun 20, 2006
Posts: 3
Thanks alot for your help I really just know that you reply for my question because I thought that I recevied notion for replying by my email but I receive nathing
I agree. Here's the link:
subject: validLetters()