• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error: cannot find symbol

 
Derek Chimbwanda
Greenhorn
Posts: 21
Linux Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

(Beginner)
When I try to compile  the code below I get the below error (7 in total),



May you advice where I am going wrong???


 
Paweł Baczyński
Bartender
Posts: 1917
37
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler is saying that it has no idea what is the censor method.
You don't have it in your code.
 
Derek Chimbwanda
Greenhorn
Posts: 21
Linux Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pawel,

And how do I fix that?

Thanks.
 
Paweł Baczyński
Bartender
Posts: 1917
37
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have code for censor method?
 
Derek Chimbwanda
Greenhorn
Posts: 21
Linux Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to sound funny, but what is code for censor method?

An absolute beginner with a surface grasp of syntax and simple program semantics.

Regards,
 
Paweł Baczyński
Bartender
Posts: 1917
37
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This line from your code means:
- Declare a variable of type String named c1.
- Call the method censor with parameter of type String and value "short".
- Assign the result of the method call to the variable c1.

Now, there is no code for the method censor in your code.
So, the compiler does not know what to do and fails.

The method should look like this:And what does it mean to "censor" a String? I don't know. It's up to you (or the person that teaches you).
 
Derek Chimbwanda
Greenhorn
Posts: 21
Linux Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Pawel,

Getting the jest of it now, however, after this adjustment you recommended:



Down to 3 errors now :-)

PartA2.java:6: error: ';' expected
    String censor (String value) {
                 ^
PartA2.java:6: error: ';' expected
    String censor (String value) {
                               ^
PartA2.java:9: error: ';' expected
return result
             ^
3 errors


Where have I gone wrong?
 
Liutauras Vilda
Sheriff
Posts: 3049
126
BSD VI Editor
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Derek, welcome to the Ranch.

Somehow I feel you started coding a bit too early, no, not in general, but in this particular exercise.

Do you have clear requirements defined for yourself what you need to accomplish? Have you tried first to write some pseudo code in simple English?
It looks at the moment that you're hunting down the syntax errors, but apart from that you're unsure what in general you're trying to achieve here. Is that true?

I'm asking all that, because you seem to be trying to solve your exercise in one go, which may be too complex to solve it that way. You need to try no to solve complex problems in one go, but rather break it down to the smaller problems and solve them separately and then link them up.

I'm reading a requirement you stated as: - Call the method censor with parameter of type String and value "short".
For me this doesn't sound correct to have method name as censor (if I'm not wrong about this word meaning in this context). Is it from official instructions you have been given?
 
Derek Chimbwanda
Greenhorn
Posts: 21
Linux Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vilda,

Firstly, thanks for taking the time to write such a detailed and advisory message. Much appreciated.

Yes I am a complete beginner with a basic grasp of simple coding and the syntax and semantics of a couple lines of code.

You are very right, to eat an elephant in a way that makes sense is one bite and a time

However, it is imperative that I complete this particular exercise soonest so I have to do a crash problem solving; then will use that as a barometer for improvements as I reflect.

So any help you may offer is greatly appreciated.

I understand the principles but more will unfold with experience I would like to believe.

Lastly, the instructions in the code are as official as they are laid out in the one I posted.

With thanks,
 
Liutauras Vilda
Sheriff
Posts: 3049
126
BSD VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Derek Chimbwanda wrote:Lastly, the instructions in the code are as official as they are laid out in the one I posted.
I'm sorry, but I don't seem to be able to find them. Could you post once again the description of the program you need to write?

By the description I mean something similar to: "...write the program, which does that and that... and...".
 
Derek Chimbwanda
Greenhorn
Posts: 21
Linux Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again Vilda,


Instruction: It is your job to write the methods that will make the statements in the main method work, the program as a whole should compile similar to below:

An example output of the completed PartA2 class
*****
****************
*************************
Outlook unclear
Without a doubt
Concentrate and ask again
Yes
Yes
Without a doubt
Very doubtful
Yes
Outlook unclear
Concentrate and ask again
Outlook unclear
Don't count on it
Without a doubt
Yes
Concentrate and ask again
Concentrate and ask again
Outlook unclear
Yes
Don't count on it
Very doubtful

**********
**********
**********
 
H. Case
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vilda, looks like a magic 8-ball...type of deal.
 
Liutauras Vilda
Sheriff
Posts: 3049
126
BSD VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
H. Case wrote:vilda, looks like a magic 8-ball...type of deal.
Thanks for hint, never heard about it before, but looked up on Google.

Derek Chimbwanda wrote:Instruction: It is your job to write the methods that will make the statements in the main method work
These are obvious low level technical requirements that statements in the main method should work. Apart from that, you don't seem to be able to explain what you actually need to do - that is the main problem I think at the moment.

Derek Chimbwanda wrote:... the program as a whole should compile similar to below
When the program compiles it has no chance to give such output you showed us, nor has the chance to give any output (apart from compilation errors in case of any, but isn't a program's execution output). You can get an output when you execute your program, that is different from compilation.

So, once again. Can you explain in English, step by step, what is your task? It is important to crystallise it, because it holds the suggestion on what methods you need to create in order to break down your task into simpler pieces.

On the technical part, please look up on how methods are being defined. You can't define method within method as you did on line 6. This supposed to be outside main() method.
 
Derek Chimbwanda
Greenhorn
Posts: 21
Linux Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again Vilda,

I have literally been smoking my socks, my sincere apologies for being vague and quite unprocessed in my writing.

And thank you so much for taking your precious time to try and decode and assist on what had bricked my complete beginner mind these past few days.

I have however, learnt a lot from your insights.

You have no idea what a slight hint can do especially when it comes to programming; and you have diligently and patiently provided that.

This is humanity at its best, thanks for being so generous.

Daniel has however helped me and problem is solved.

The program compiles and runs without a glitch now :-)

 
Tony Docherty
Bartender
Posts: 3101
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Derek Chimbwanda wrote:Daniel has however helped me and problem is solved.

Actually he hasn't helped you, he gave you a solution but in reality he has probably hindered you.

Being given a solution solves your immediate problem but doesn't teach you anything so when you get your next assignment you won't have learned as much as you should have done and so the next assignment appears even more difficult. If this happens with a few consecutive assignments there is a serious danger you'll suddenly find you are so far out of your depth you have no chance of completing any further assignments or exams.

My advice is ignore the solution you were given and see if you can write the code yourself.
 
Liutauras Vilda
Sheriff
Posts: 3049
126
BSD VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from the great lesson by Tony, in daniel's provided solution were serious coding problems. I'd go with Tony's advice.

daniel, please remind yourself how Strings are being checked for their equality. The style you used is very poor and in fact very unreliable, in short - wrong.
 
Derek Chimbwanda
Greenhorn
Posts: 21
Linux Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Tony, your advice is priceless.  I can however, confirm Daniel is now directly helping me through mobile.

@Vilda, I will clarify your concerns on the code with Daniel.

Much thanks to you guys!

 
Derek Chimbwanda
Greenhorn
Posts: 21
Linux Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After a TeamViewer Collaboration (2 hours) with Daniel, this is the new code.

Thank you all for the help; I have a hang of it now.

 
fred rosenberger
lowercase baba
Bartender
Posts: 12297
36
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is the complete, total, and absolutely WRONG way to test for string equality.  Sure, it may work for this example, but if you don't discover the correct way to test for String equality soon, you will be in a world of trouble.
 
Derek Chimbwanda
Greenhorn
Posts: 21
Linux Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fred,

What is the correct way then?
 
Campbell Ritchie
Sheriff
Posts: 52055
90
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Derek Chimbwanda wrote:. . . What is the correct way then?
We have an FAQ about it.
 
Tony Docherty
Bartender
Posts: 3101
61
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Derek Chimbwanda wrote:@Tony, your advice is priceless.  I can however, confirm Daniel is now directly helping me through mobile.

Be very careful getting private help from one person unless you know the person is genuinely qualified to help you. The beauty of sites like JavaRanch is if someone gives you poor or misleading advice someone else will spot it and correct the mistake, you don't get that safety net with one to one help.
 
Derek Chimbwanda
Greenhorn
Posts: 21
Linux Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ritchie thank you a lot, very handy link
 
Dave Tolls
Ranch Hand
Posts: 2208
20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing I would note...the number of '*' is exactly the same as the length of the String passed in.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!