Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 4. (SlotMachine.java and SlotMachineTester.java)A slot machine has three integer data fields one for each of thevalues displayed to the user. Think of them

Question 4. (SlotMachine.java and SlotMachineTester.java)A slot machine has three integer data fields – one for each of thevalues displayed to the user. Think of them as item1, item2and item3. It also has a single double data field calledmoney that keeps track of how much money the player hasleft.

In addition it should have the following:

- A constructor that sets the value of each of the items to anappropriate random value. Remember how the slot machineworks, each item has 7 possible values (this can be done by callingthe spin method described below). The constructor takes asingle argument an integer that sets the initial amount of money inthe machine.

- A mutator called cashOut that takes no arguments and reducesthe money in the machine to 0 and returns whatever the previousbalance was.

-A mutator method called spin that changes the three data fieldsto random values.

-An accessor method called displayResults that shows the resultof the spin to the user. This should return a single stringwith the word value of the results, not the integer value(eg. “seven, seven, cherry”).

This is a great place for a “helper” method that is designed totake in an integer as an argument and return the appropriate wordvalue for the item.

-A mutator method called adjustMoney that takes noarguments. Instead it is called after the spin method toeither add or remove the appropriate amount of money to theplayer’s total. This method determines if there was a win orloss. If there are two matching items the player wins $2, ifall three matched they win $10, if none match they lose$1.

-***Write JavaDoc comments for this class.***
Write a tester program that does the following:

- Prompt the user for an initial amount of cash to put into themachine. If the amount is less than 0 or greater than 100display an error message and exit. Otherwise, use the amountto create the slot machine object and display the initial results(this is not a win or loss, just a display).

- Ask the user if they want to spin or cash out. oIf they cash out, tell them their total and end the program. , Ifthey spin proceed accordingly – have the machine spin and adjustthe player’s total. Display the results and the new playertotal (money) after each spin.

-Continue to prompt the user to cash out or spin until theychoose to leave or their money reaches $0.

Step by Step Solution

3.48 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

This class is used to create a slot machine It has three integer data fields one for each of the values displayed to the user and a double data field called money that keeps track of how much money th... 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

Stats Data And Models

Authors: Richard D. De Veaux, Paul D. Velleman, David E. Bock

4th Edition

321986490, 978-0321989970, 032198997X, 978-0321986498

More Books

Students also viewed these Programming questions

Question

What are related party transactions?

Answered: 1 week ago

Question

How does visua lization w ork? (p. 2 80)

Answered: 1 week ago