aspose file tools*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Switch Case" Watch "Switch Case" New topic
Author

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.


SCJP 6, OCMJD 6, OCPJWSD 6
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
Sheriff

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
sscce.org
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36520
    
  16
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: http://aspose.com/file-tools
 
subject: Switch Case
 
Similar Threads
how do i loop not using a for statement?
Do while error, I'm going crazy
Keep getting this error and not sure why
Switch case
switch statement