dimanche 8 mars 2020

Slot Machine Project utilizing arrays and methods in Java

Write the body of the method int calculateWinnings(int[] wheelNums).

• Assume the input array has three elements and check it for each winning condition. Return the correct number of tokens for each case.

• Print the notification that corresponds to the number of tokens returned


I'm no fast thinker but I usually have ideas. basically, this is just one method that will be called from the MAIN method. For now, I just want to understand and solve the bullet points.

I thought of using for loops with counters to take account of conditions such as the sequence of a 3 slot machine. Assume there are OTHER METHODS that take care of what's left than this method. HERE IS THE SAMPLE OUTPUT: NOTE BOLD IS THE USER INPUT

  • Java Slot Machine

  • Tokens: 10
  • Press enter to play (spend 1 token) or type 'quit' to stop.
  • Spin: [3, 6, 7]
  • Sorry, you lost :(
  • Tokens: 9
  • Press enter to play (spend 1 token) or type 'quit' to stop.
  • Spin: [2, 4, 2]
  • Pair! You win 1 token.
  • Tokens: 9
  • Press enter to play (spend 1 token) or type 'quit' to stop.
  • Spin: [3, 2, 4]
  • Sequence! You win 2 tokens.
  • Tokens: 10
  • Press enter to play (spend 1 token) or type 'quit' to stop.
  • Spin: [4, 4, 4]
  • Triple 4s! You win 12 tokens.
  • Tokens: 21
  • Press enter to play (spend 1 token) or type 'quit' to stop.
  • quit
  • You quit with 21 token(s).
  • Your net profit is 11 token(s).



Aucun commentaire:

Enregistrer un commentaire