Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Assignment: In Lab4 you are going to add more functionalities to the Gambling Slot Machine from lab3. Write an application that allows the user to

Assignment: In Lab4 you are going to add more functionalities to the Gambling Slot Machine from lab3. Write an application that allows the user to play repeatedly. Ask the user to enter the dollar amount the user is willing to gamble or zero to quit. Keep track of the total amount of money won, the total amount of money inserted into the slot and the cumulative balance. There is a cap on the cumulative amount lost or won. The player cannot continue playing when the cumulative balance is $50 or more or when the cumulative balance is $50 or less. If the game stops because the player won, $50 or more display the following pattern of happy faces. You must use a nested loop to create the pattern. :) :) :) :) :) :) :) :) :) :) If the game stops because the player looses, $50 or more display the following pattern of sad faces, using a nested loop. :( :( :( :( :( :( :( :( :( :( Note: Pick randomly three fruits out of five fruits. Below is an example of the program's output: Enter the dollar amount you want to play OR 0 to quit: 40 *APPLE* *CHERRY* *BANANA* Sorry, you lost Balance: 40 Enter the dollar amount you want to play: OR 0 to quit: 40 *CHERRY* *PINEAPPLE **CHERRY* Congratulations, you won $40 Balance: 40 Enter the dollar amount you want to play: OR *CHERRY* *APPLE* *PINEAPPLE Sorry, you lost Balance: 80 OOOPS, YOU LOST $50 or more YOU CAN'T PLAY ANYMORE :( :( :( :( :( :( :( :( :( :( Total Money Spend120 Total Won40 Balance80 Another example: Enter the dollar amount you want to play OR 0 *PINEAPPLE ** PINEAPPLE **CHERRY* Congratulations, you won:$20 Balance: 0 Enter the dollar amount you want to play] OR *APPLE* *BANANA* *ORANGE* Sorry, you lost Balance: 20 Enter the dollar amount you want to play] OR *PINEAPPLE *APPLE* *APPLE* Congratulations, you won:$20 Balance: 20 Enter the dollar amount you want to play] OR *CHERRY** PINEAPPLE **CHERRY* Congratulations, you won:$20 Balance: 20 Enter the dollar amount you want to play] OR *PINEAPPLE **APPLE** PINEAPPLE* Congratulations, you won:$20 Balance: 20 Enter the dollar amount you want to play] OR *ORANGE** PINEAPPLE **CHERRY* Sorry, you lost Balance: 40 Enter the dollar amount you want to play] OR 0 to quit: 40 to quit: 20 0 to quit: 20 0 to quit: 20 0 to quit: 20 0 to quit: 20 0 to quit: 20 0 to quit: 30

*CHERRY* *CHERRY* *CHERRY* Congratulations, you won Tripple $$$:90 Balance: 20 Enter the dollar amount you want to play] OR 0 to quit: 50 *PINEAPPLE **CHERRY* *ORANGE* Sorry, you lost Balance: 30 Enter the dollar amount you want to play] OR 0 to quit: 50 *BANANA* *CHERRY* *CHERRY* Congratulations, you won:$50 Balance: 30 Enter the dollar amount you want to play] OR 0 to quit: 50 *APPLE* *BANANA* *APPLE* Congratulations, you won:$50 Balance: 30 Enter the dollar amount you want to play] OR 0 to quit: 50 *ORANGE* *BANANA* *APPLE* Sorry, you lost Balance: 80 OOOPS, YOU LOST $50 or more YOU CAN'T PLAY ANYMORE :( :( :( :( :( :( :( :( :( :( Total Money Spend 350 Total Won 270 Balance 80

Objectives: Lab 3: Conditional Logic Performing decisions using if and switch statements Using relational and logical operators Working with random numbers Assignment: Gambling Write an application that simulates a gambling slot machine. In the application, perform the following tasks: 1. Prompt the player to enter the amount of money that the player is willing to gamble. 2. Create three random numbers in range from one to four to represent three of the following four objects (Apple, Orange, Cherry and Pineapple). 3. Compare the numbers for equality and calculates the prize. o If all three numbers are the same, the player wins three times the amount inserted. o If two objects are the same the player wins back the amount inserted (gets the money back), otherwise the player wins $0. 4. Display the randomly selected objects (fruits names, not integers). Use switch or if else statements to examine the randomly created integers in order to display the corresponding fruits. 5. Display the dollar amount that the player wins. 6. Here is an example what the program should do: Enter the dollar amount inserted into the slot machine: 100 Orange Apple Cherry Sorry, you lost Or Enter the dollar amount inserted into the slot machine: 100 Orange Cherry Cherry Congratulations, you won $ 100 Or Enter the dollar amount inserted into the slot machine: 100 Orange Orange Orange Congratulations, you won $ 300

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java Programming

Authors: Joyce Farrell

9th edition

1337397075, 978-1337397070

Students explore these related Programming questions