The above payout is not correct. Only two "CHERRIES" are being counted, not three "CHERRIES". The correct payout should be $20. All else works correctly in the program and in this method. This one problem is driving me crazy. Can someone help me, please?
I would suggest you put those values into an array, then you can iterate the array with a for loop and increment the chrry count. Your three‑element array will give you a cherry count of 3 (I hope). Much neater than those multiple ifs.
It might also be possible to use an enumerated type rather than Strings. Then you can respectably use == CHERRY and not need the equals() method.
And even if you fix those, I suspect you still won't get that output from that code (although that is based on just looking at the code, not running it, so I may be wrong).
Reply to Sheriff Campbell Ritchie: Thanks for your suggestion about using an array, but I am a greenhorn and I have not studied arrays yet, however now may be the time to do just that. On the other hand, I would like to see if I can write my if...else statements correctly so that my cherry jackpot pays correctly like my BAR and 7 jackpots do.
Thanks for all the help,
No, you shouldn’t; the middle pair of () is redundant because the dot operator has a higher precedence than the bang operator !. You can use the () if you wish, but they are not necessary. If you were using && as well, you might need () because bang has a higher precedence than &&.
lee shotwell wrote: . . . I should bracket "not equal" like this: if(!(s1.equals("CHERRIES"))) . . .
That is not going to produce any errors. Your errors must be elsewhere.
Your many if blocks for counting the cherries look unwieldy to me. I think you ought to change them.
Most slot machines that I've played (not that I'm an expert) work like this:
CHERRY - CHERRY - BAR = 10 points
CHERRY - BAR - CHERRY = 3 points
If order does matter, then you can simplify your if statements with one nested if.
Reply to Bill Clar: Here are the rules to my slot machine (a.k.a. one armed bandit) and yes, order does count.
1. Each of the 3 positions in the String could be one of the following: "BAR", "7", "CHERRIES" or "SPACE".
2. Each of the 3 output positions are determined randomly with a 25% chance of any one of the 4 in any position.
3. Here are the combinations that should pay the bet as shown:
CHERRIES [not CHERRIES] [any] pays 3 x the bet
CHERRIES CHERRIES [not CHERRIES] pays 10 x the bet
CHERRIES CHERRIES CHERRIES pays 20 x the bet
BAR BAR BAR pays 35 x the bet
7 7 7 pays 50 x the bet
My problem has been with the CHERRIES and making sure that a payout occurs only when they appear in the above positions. The second problem: If the CHERRIES appear in the correct position, my method must count them correctly so that the payout is correct. Currently, my method only counts two CHERRIES, hence the payout is for only two CHERRIES when actually all positions have CHERRIES. My method works fine with all the other combinations. In the beginning, my method was counting the CHERRIES when they appeared in any position. I have spent a lot of time getting rid of those errors and now I have one remaining. I have not tried a nested if yet, like you suggested so I will try that and let you know how it works.
lee shotwell wrote:My problem has been with the CHERRIES and making sure that a payout occurs only when they appear in the above positions. The second problem: If the CHERRIES appear in the correct position, my method must count them correctly so that the payout is correct.
Sounds to me like you're overthinking this.
My advice: StopCoding (←click) and write out your combination logic in English.
It seems to me that you're getting yourself tied up in knots trying to work out all the combinations, rather than looking carefully at your rules.
Tip: What should you do if the first position is NOT a cherry? That might get you started in the right direction.
My unwelcome suggestion would have been to remove that black wire leading from the computer to the wall.
Winston Gutkowski wrote: . . . My advice: StopCoding (←click) and write out your combination logic in English.
. . .
[not CHERRIES] CHERRIES CHERRIES appeared. Here is my output.
I respect what you have said to me. I know that my method does not cover that situation (where position one is not a CHERRIES) but as you can see my output is fine. However, you may be hinting that that the reason my code does not count CHERRIES CHERRIES CHERRIES correctly because I have not included those situations in my if..else statements. At any rate, Winston I will stop coding and work out my logic first and then enter it into my code. In closing though, I am somewhat confused. Tomorrow I must take my family shopping, but the following day I will go to a cafe away from my computer and try to work out the logic. I have the bad habit of firing up my Eclipse Europa compiler and doing the logic and code at the same time.
Both of you have helped me a lot, thanks again. Winston, concerning the use of the shoe in blackjack, it is best to find a dealer using one deck and a full table. Remember, you are playing against the dealer and with a full table the face cards should come out quicker on the other hand, if you play one on one with the dealer it is easier to know the exact count. If you know that all the face cards are out, except for the king and ace in your hand you can bet the ranch and you will feel like a power ball winner. Pit falls? It is hard to find a one deck game and the dealer will often only play through half the deck or less, then he grabs a new deck. Furthermore, if the house knows you are counting, chances are, you will be asked to leave. Have a nice weekend.
Basically this saying if both s2 and s1 have cherries and s3 either has or does not have a cherry increment the count. Or to put it more concisely if both s2 and s1 have cherries increment the count. You could leave off the s3 check and remove the else part of the statement.
EDIT: BTW when posting code please make sure it is the code you are running - the code posted won't compile as there are missing closing brackets on the Bar and 7 if statements