The Artima Developer Community
Sponsored Link

Java Answers Forum
Using a method in another method

2 replies on 1 page. Most recent reply: Nov 29, 2002 12:08 PM by Doug Schwartz

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Matthew Pica

Posts: 5
Nickname: mrpica05
Registered: Nov, 2002

Using a method in another method Posted: Nov 28, 2002 5:47 PM
Reply to this message Reply
Advertisement
Ok, i searched the forum for "unresolved problem" and I either didnt understand something that could have helped me or it wasn't pertinant to my problem. So here goes and hopefully someone can lend a hand.

I have a method with in my program that is called "public static boolean beginsWithVowel(String word)" I then have a method called "public static String translateWord(String word)." I would like to use the first method I mentioned to in the second method i mentioned.

What i have to do is this, if a word starts with a vowel, i need to translate it to pig latin my concatenating "yay" to the end of that word. I call the first method like thus...."
if(word.beginsWithVowel())
{
word = word + "yay ";
}"
however i get an error which is the following "
cannot resolve symbol
Symbol :method beginsWithVowel ()
location: class java.lang.String
if(word.beginsWithVowel())
^

No help available"

No idea what the hell that means, i though you could use a method in another method. It is all within the same class so i dont know why it cant find it...
My IDE is BlueJ version 1.2.2 (Java version 1.4.0)
im running Win2k Pro i saw someone ask this stuff in the other posts so i thought i would tell you it.

If anyone can tell me my(and im sure its a simple one) mistake i would greatly appreciate it.


Matthew Pica

Posts: 5
Nickname: mrpica05
Registered: Nov, 2002

Re: Using a method in another method Posted: Nov 28, 2002 8:25 PM
Reply to this message Reply
I actually had an epiphany and the answer just came to me. Dont really know how or why but it works now...

if(beginsWithVowel(word)
.
.
.
return translatedWord;

NICE! Thanks anywho :^ )

-Matthew

Doug Schwartz

Posts: 1
Nickname: snoopdoug
Registered: Nov, 2002

Re: Using a method in another method Posted: Nov 29, 2002 12:08 PM
Reply to this message Reply
The reason word.beginsWithVowel() doesn't work is that word is a string and string is final, so you cannot extend that class.

Since beginsWithVowel() is static, you use it without a class instance. Since you are in the class, the "this." part is assumed.

I'd suggest you find a tool that supplies syntax highlighting (not a full-blown IDE as that will mask your shortcoming) and possibly auto-completion. That way when you type beginsWithVowel(, the tools will show you "String)"...

doug

P.S. Try IntelliJ's Idea (http://www.intellij.com/idea/). It's cheap (~$100) for students.

Flat View: This topic has 2 replies on 1 page
Topic: FTP in java Previous Topic   Next Topic Topic: whether java run in unix can call java in win NT

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use