• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the do loop, the first if doesn't have a matching }
 
Greg Cook
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any special reason why you initialize
your variables (including counter) with character literals?
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't do:
counter = counter++
Try doing this instead:
counter++
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why pick something like this for a first application? Start low and learn the basics.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greg Cook
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want to initialize your numeric values to 0 not '0'!
Try that.
int totamount=0;
 
Greg Cook
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic