Java program help Simulate a slot machine. The customer will add a fixed amount of money to the machine and play the slots. There should be 4 images for the game: "Apple", "Orange", "Banana", and "Cherry". If three of the images match, the customer wins $2 and is added to their balance. If all four match, the customer wins $10 and that is added to their balance. If less then four match there is no prize money, and the customer is charged $1 for the try. The customer can quit after each try, and the program will print out the customer's cash balance. Coding Details: Use an array of strings to store the 4 strings listed above.  Use a do-while loop for the program. The program starts once the user enters how much money they have. The decision to stop occurs at the bottom of the loop. The do-while loop keeps going until the user quits, or there is no money left. The pseudocode for the program is shown below: Determine the fruits to display (step 3 below) and print them Determine if there are 3 or 4 of the same image Display the results Update the customer balance as necessary Prompt to play, or quit Continue loop if customer wants to play and there's money for another try. Use the Random class to generate a random number between 0 and 3. This random number will be an index into the array of strings. Add the string at that index to an ArrayList. This should be done four times.  When finished the ArrayList will contain 4 strings that represent randomly selected fruit images. Write a custom method that is called within the do-while loop. This method will accept the array list as a parameter, and it will return an integer that represents the number of times an 'fruit' appeared in the array list.  Inside this method, use the frequency method from the Collections class to determine how many times a particular value is in a ArrayList. The Collections.frequency should be called for each image to get the counts by image. If your custom method returns a three, then add $2 to the balance. If it returns a four, then add $10 to the customer's balance.  Display the contents of the arraylist on the same line with spaces between them.  Display the results of the play and the current balance. At the bottom of the do-while loop, prompt the user if they want to continue to play (P) or to quit (Q). Case should not matter. If the user enters a character other than those two characters, treat anything other than a 'Q' as the starting point. Sample Output Enter dollar amount to play --> 5 Apple Apple Orange Orange  << Not a winner this time >> Balance is: $4 Play Again (P) or Quit (Q) --> P Banana Banana Orange Cherry  << Not a winner this time >> Balance is: $3 Play Again (P) or Quit (Q) p Banana Apple Banana Banana  << You matched 3!  That's $2 >> Balance is: $5 Play Again (P) or Quit (Q) q Thanks for playing!  Cash Balance is $5 I appricate any help

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java program help

Simulate a slot machine.

The customer will add a fixed amount of money to the machine and play the slots.

There should be 4 images for the game: "Apple", "Orange", "Banana", and "Cherry".

If three of the images match, the customer wins $2 and is added to their balance. If all four match, the customer wins $10 and that is added to their balance. If less then four match there is no prize money, and the customer is charged $1 for the try. The customer can quit after each try, and the program will print out the customer's cash balance.

Coding Details:

  1. Use an array of strings to store the 4 strings listed above. 
  2. Use a do-while loop for the program. The program starts once the user enters how much money they have. The decision to stop occurs at the bottom of the loop. The do-while loop keeps going until the user quits, or there is no money left. The pseudocode for the program is shown below:
    • Determine the fruits to display (step 3 below) and print them
    • Determine if there are 3 or 4 of the same image
    • Display the results
    • Update the customer balance as necessary
    • Prompt to play, or quit
    • Continue loop if customer wants to play and there's money for another try.
  3. Use the Random class to generate a random number between 0 and 3. This random number will be an index into the array of strings. Add the string at that index to an ArrayList. This should be done four times.  When finished the ArrayList will contain 4 strings that represent randomly selected fruit images.
  4. Write a custom method that is called within the do-while loop. This method will accept the array list as a parameter, and it will return an integer that represents the number of times an 'fruit' appeared in the array list. 
    • Inside this method, use the frequency method from the Collections class to determine how many times a particular value is in a ArrayList. The Collections.frequency should be called for each image to get the counts by image.
  5. If your custom method returns a three, then add $2 to the balance. If it returns a four, then add $10 to the customer's balance. 
  6. Display the contents of the arraylist on the same line with spaces between them. 
  7. Display the results of the play and the current balance.
  8. At the bottom of the do-while loop, prompt the user if they want to continue to play (P) or to quit (Q). Case should not matter. If the user enters a character other than those two characters, treat anything other than a 'Q' as the starting point.

Sample Output

Enter dollar amount to play --> 5

Apple Apple Orange Orange 
<< Not a winner this time >>

Balance is: $4
Play Again (P) or Quit (Q) --> P

Banana Banana Orange Cherry 
<< Not a winner this time >>

Balance is: $3
Play Again (P) or Quit (Q) p

Banana Apple Banana Banana 
<< You matched 3!  That's $2 >>

Balance is: $5
Play Again (P) or Quit (Q) q

Thanks for playing!  Cash Balance is $5

I appricate any help!

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education