• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

validLetters()

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
validate();
}
thanks alot
sara
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

CR
 
sara salem
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic