File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Switch Case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Switch Case" Watch "Switch Case" New topic

Switch Case

Mathew Mintalm
Ranch Hand

Joined: Feb 21, 2010
Posts: 103

Hello, would be great if someone can help me.

So I'll try to describe my problem.

So I have code with switch case, something like:

I made some kind of lottery, which selects a random option from this switch case.

I now Im wondering how to disable choosing the same option once again.

For example, in my last lottery choosen option was case1, so now i would like to disable this case in next lottery.

Please help me, thanks in advice.
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
One way would be to remember what was your last result from random, and if it matches your newly picked number, just keep picking them till they don't match. Better solutions would include some kind of a Collection, ie. a Set. Once you draw your number you remove it, next time you pick from what is left in your bag.

I no good English.
Mathew Mintalm
Ranch Hand

Joined: Feb 21, 2010
Posts: 103

Yes, I have to think about how to do it.
marc weber

Joined: Aug 31, 2004
Posts: 11343

Note that the key to Martin's suggestion is about how you select the number in the first place -- not in "disabling" cases.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46420
marc weber wrote:-- not in "disabling" cases.
I haven't looked at your problem in any sort of detail, but I suspect it will be better with the switch block replaced by something totally different.
I agree. Here's the link:
subject: Switch Case
It's not a secret anymore!