Hello! For my computer science class, I have to convert a program with global variables to a program with all instantiated variables. I tried... and, well, the program works. Java gets it! But, I do have 24 errors.

So you can see the string variables and such that I tried to incorporate into the new code, but I can't figure out what else I can do to get rid of the errors. Here is my error list, should you also require that to assist me:

Also, here is what consists of the text file I'm using for the input stream:

Code :

XQAC ZVM
PDAE AV
SNIC SY
AAAB BB

Essentially, I am given a fictional word, and need to add a fictional suffix to the end. My main problem with the program, as you can see, is that I am having trouble declaring variables properly. If you would like the assignment prompt, please say so, as I would be happy to offer any documents that would help you help me!

Thank you in advance!

January 16th, 2012, 08:36 PM

helloworld922

Re: Where are all the symbols!? Poor Java can't find them... :(

A few things to keep in mind:

1. You must declare and initialize your variables before you use them.

2. A local variable's scope exists entirely inside of the block it was declared in. When you enter that block, that variable is "created" and comes into scope. When you leave that block, that variable goes out of scope and can no longer be used. Note that when you re-enter the block, even though the variable may have the same name, it must be created because the old variable has gone out of scope and no longer exists.

3. Scopes can nest. So variables declared in a block is accessible from every block nested inside of the block it was declared in as long as it follows rule 1.

I think these rules should be able to solve every one of your compile errors.

Here, on each iteration through the for loop you're re-creating the variable wordR, then trying to initialize it to some string + wordR. But what is wordR? You haven't initialized it yet for that iteration, and whatever variable existed prior no longer exists. So what is being add to the end word.substring(i,i+1)? The compiler has no idea, and that's why it's complaining. So how should you fix this problem? Hint: take a look at rule 3 and rule 1.

Take a look at the compiler output and go to the lines it's complaining about. Try to apply the above rules and see if you can't figure out how to solve the other compiler errors.

January 16th, 2012, 09:45 PM

coffecupcake

Re: Where are all the symbols!? Poor Java can't find them... :(

Thank you, I will try looking at all of these and see where I get. I got it down to one error, but when I fix that one error, another pops up somewhere! Frustrating.

Thanks again!

January 17th, 2012, 01:53 PM

coffecupcake

Re: Where are all the symbols!? Poor Java can't find them... :(

I've been trying to fix this but it keeps telling me that my variables have not been initialized. I'm getting very confused and frustrated.. Help?
Here's my attempt at fixing the code...