Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want design and implement an application that simulates a simple slot machine in which three numbers between 0 and 9 are randomly selected and

I want design and implement an application that simulates a simple slot machine in which three numbers between 0 and 9 are randomly selected and printed side by side. Let print an appropriate statement if all three of the numbers are the same, or if any two of the numbers are the same. Then play until the user chooses to stop.

Note:

This program should be build using three classes:Slot,SlotMachine, and your driver. TheSlotandSlotMachineclass will work similar to theDiceandPairOfDiceproblem done in chapter 4. TheSlotclass will have an instance data value that is randomly set to a value in the range of 0-9 when a method namedspin()is invoked (similar to what theroll()method of theDieclass did for theDieobject). TheSlotclass should only have a getter for its value. Override thepublic boolean equals(Object obj)method on theSlotclass so that the method returnstrueif theSlotvalueis the samevalueas theSlotpassed into the method. TheSlotMachineclass will have instance data for threeSlotobjects. TheSlotMachineclass should provide getters that return the int value for each slot, and have no setters. TheSlotMachineclass should have a method namedspin()that spins each slot. Build a method on theSlotMachineclass namedresult()that returns aintindicating the results of the recent most spin. Use theequals()method of theSlotclass to compare values. Theresult()method should only return three values:3if all three match,2if two match, and0if no slots match. Also build a method on theSlotMachineclass named resultStr()which returns aStringthat is used to show the results of the slots (the string returned will look like this: "| 0 | 4 | 3 |"). Instantiate and use aSlotMachineobject in your driver class.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

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

Microeconomics An Intuitive Approach with Calculus

Authors: Thomas Nechyba

1st edition

978-0538453257

Students also viewed these Programming questions