[Bluej-discuss] syntax of method calling (not really)

chen li chen_li3 at yahoo.com
Wed Jul 12 17:46:24 BST 2006


--- Stephen Bloch <sbloch at adelphi.edu> wrote:
>>    public String do_revComSeq()
> >         {
> >            String revComSeq= new 
>
>StringBuilder(do_comSeq()).reverse().toString().toUpperCase();
> >             return revComSeq;
> >           }
> 
> Wouldn't it be simpler to just call do_comSeq on the
> result of 
> do_revSeq, or vice versa?

But there is no reverse method in String class. In
order to reverse a string it must be passed to
Stringbuilder first then changed back to string using
toString method afer calling reverse method. This is
the only way I know how to do it in java.  


> 
> Oh, no, I see, you've still got both of those
> methods operating on 
> the instance variable "seq" rather than on a
> parameter, so you can't 
> call one on the result of the other.  If you wrote
> all three methods 
> to take in a String parameter and return a String
> result, you could 
> combine them easily:
> 
> public String do_revComSeq(String seq)
>     {
>     return do_revSeq(do_comSeq(seq));
>     }
>
 
If I have methods operating on parameters I need to
type them from the popup windows and in the future my
string comes from a file, I don't think it is doable
for me. 
 
> Alternatively, you could have each method return a
> SeqReader instead 
> of a String, and write
> 
> public SeqReader do_revComSeq ()
>     {
>     return this.do_comSeq().do_revSeq();
>     }
> 
> Either of these approaches would be much more
> flexible and elegant 
> than the current version.
> 

I try both code fragments above on my BlueJ. But they
don't work. I don't how to fix them at this
monent(sorry I am currently in the middle of chapter 3
only). But your ideas are very innovative to me. I
think I should follow them in the future.

Once again thank you very much,

Li 


Li 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the bluej-discuss mailing list