aspose file tools*
The moose likes Beginning Java and the fly likes Alright, my eyes hurt from staring at this monitor trying to figure this out. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Alright, my eyes hurt from staring at this monitor trying to figure this out." Watch "Alright, my eyes hurt from staring at this monitor trying to figure this out." New topic
Author

Alright, my eyes hurt from staring at this monitor trying to figure this out.

Greg Cook
Greenhorn

Joined: Oct 03, 2002
Posts: 7
This is my first program and it is giving me so many errors. It seems like as soon as I get rid of one error, two or more pop up in their place!
I really need some help with this, where is my big error(s)?
I keep getting a " 'case'outside of switch" error after the first case.

[ October 03, 2002: Message edited by: Thomas Paul ]

Aspiring newbie in the Java world.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
In the do loop, the first if doesn't have a matching }


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Greg Cook
Greenhorn

Joined: Oct 03, 2002
Posts: 7
Thank you. That did fix my problem. But, just like I said before. Once that problem was out of the way, 11 more popped to take its place.
Now all my variables are saying:
"App.java": Error #: 553 : variable totalOTPay might not have been initialized at line 66, column 28
Or something very similar with the variable name and locations being different. This is getting frustrating b/c I have no one experienced to ask directly but you guys out here.
I am going to keep staring and playing with this, hopefully someone can tell me what is causing this new set of errors now.
Greg Cook
Greenhorn

Joined: Oct 03, 2002
Posts: 7
I may have figured my last problem already, but I think I went about it in the wrong way. Here's the new code:

[ October 03, 2002: Message edited by: Greg Cook ]
[ October 03, 2002: Message edited by: Greg Cook ]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You can't use a method variable until it has been initialized.
This will give an error:

int myVar;
System.out.println(myVar);

This will not:

int myVar = 0;
System.out.println(myVar);
Greg Cook
Greenhorn

Joined: Oct 03, 2002
Posts: 7
Thomas, you have been a big help so far.
I have everything working so far in case 1. I figured it out this morning, had to sleep on it I guess. I woke up and it was just there in my head.
Here's my new code:
Greg Cook
Greenhorn

Joined: Oct 03, 2002
Posts: 7
Now, I just have a problem with Case 2
It will give me a counter value = 48 no matter how many times I run it. I have moved the counter around to different areas of the program to see if it works better, but nothing seems to affect it. So, I have come to the conclusion that something external to the actual line of code is affecting it.
The loop works, the case 1 works flawless too. Just something to sort out in Case 2. And I thought that would be the easy one.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Is there any special reason why you initialize
your variables (including counter) with character literals?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You can't do:
counter = counter++
Try doing this instead:
counter++
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Oh yes you can, he did it!
That explains why once he stuffed '0' into counter,
it always stayed the same. I wonder what the decimal value of '0' is?
-Barry
Chris Stewart
Ranch Hand

Joined: Sep 14, 2002
Posts: 184
Why pick something like this for a first application? Start low and learn the basics.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
As for fixing one error and 11 more popping up, that's just the nature of the beast. My strategy when I start compiling is to just look at the first error and fix it. I don't usually worry about the other errors because, as you noticed, they can change drastically after one error is fixed. After a while, you tend to get a feeling for which errors are related and which are not.
Keep coding!
Layne


Java API Documentation
The Java Tutorial
Greg Cook
Greenhorn

Joined: Oct 03, 2002
Posts: 7
To answer some of the questions:
I have already fixed the counter++
I came to that conclusion earlier today.
Why did I pick this for my first assignment? I didn't, it was assigned this way.
I initialized the variables at '0' because it was telling me that "variable xxx may not have been initialized at row xx column xx"
So, I initialized them all to '0' to take care of the errors.
The whole program now runs fine, except that case 2 spits out nothing but '48' or '48.0' for an answer for all 4 variables. If I ran case 1, it will add 48 to the correct answer. Case 1 works flawlessly.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You want to initialize your numeric values to 0 not '0'!
Try that.
int totamount=0;
Greg Cook
Greenhorn

Joined: Oct 03, 2002
Posts: 7
Thank Thomas. I was given that solution earlier. It solved all my problems.
With some cosmetic seperator lines and spaces, it looked and ran good.
Is there any special reason why you initialize
your variables (including counter) with character literals?

Oh yes you can, he did it!
That explains why once he stuffed '0' into counter,
it always stayed the same. I wonder what the decimal value of '0' is?
-Barry

These two comments helped, after I thought about them.
I know Case 3 didn't quite work right, but I wasn't going to try to re-write half the program to have its break statement drop me out of the program. It asks you if you want to run the program again, but I didn't care. I was just happy to see the rest of the program run.
Thanks for all the help guys! This place is great.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
That's what those two weird comments were supposed
to do. Man am I weird...
If I just tell you how to fix it, you do it and
it works. If you think, then see it, then say to
youself "Oh Sh*T, why didn't I see that", a few
more neurons are fired and the connections burned in.
Suggestion: Go get these out the library and work through them
On to Java
Objects First
[ October 05, 2002: Message edited by: Barry Gaunt ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Alright, my eyes hurt from staring at this monitor trying to figure this out.
 
Similar Threads
I know its Friday night, hope somebody's here!
unreachable statement
payroll
Accepting Numeric User Input
DUE AT MIDNIGHT TONIGHT..1 ERROR..HELP