What it Looks Like to the User The program will loop, asking the user for a...

90.2K

Verified Solution

Question

Programming

What it Looks Like to the User

The program will loop, asking the user for a bet amount from 0to 100 (assume dollars, you can use ints orlongs). If the user types a 0 that means she wantsto quit. Otherwise, accept the amount as their bet and simulate aslot machine pull. Your program willprint out a line that looks like a slot machine result containingthree strings. Some examples are:  BAR 7 BAR, 7 7cherries, cherries BAR space, space BAR BAR, or cherries cherriesBAR.

  • Each of the three positions in the string could be one of thefollowing: \"BAR\", \"7\",\"cherries\" or \"space\".
  • Each of the three output positions must be generated by yourprogram randomly with probabilities:
    • space 1/2   (50%)
    • cherries 1/4 (25%)
    • BAR 1/8 (12.5%)
    • 7 1/8 (12.5%)
    • Therefore, space should be the most frequentsymbol seen and BAR or 7 theleast frequent.
  • The following combinations should pay the bet as shown (noteORDER MATTERS):
    • cherries [not cherries] [any] pays5 × bet (5times the bet)
    • cherries cherries [not cherries] pays15 × bet
    • cherries cherries cherries pays30 × bet
    • BAR BAR BARpays50 × bet
    • 7 7 7 pays 100 ×bet

The Data

It will contain three private memberStrings as its main data:string1, string2, andstring3.   We will also add a publicstatic member which is to be a final int MAX_LENset to 20. This represents the maximum length that our class willallow any of its strings to be set to. We can useMAX_LEN in the ThreeString methodwhose job it is to test for valid strings (see below).

Additionally, we want tokeep track of the winnings in an array and then print them out atthe end of the program. The static int array will be calledpullWinnings and have a size equal to MAX_PULLS (a static finalint), which will be set to 40.

boolean saveWinnings(int winnings), and StringdisplayWinnings()

Create two more methodsfor the pullWinnings array. One will save the winnings from theround, boolean saveWinnings(int winnings), and the other will use aloop to get the values out of the array as well as the totalwinnings and return a string, String displayWinnings(). Call bothmethods from the main. saveWinnings() will return a booleanaccording to whether there was space to save the incoming value ofwinnings. If it returns false, then have the main stop playing thegame. displayWinnings() should also be called from the main, whereit will print the returned string.

Where it All Goes

You can create theThreeString class as a non-public class directlyin your client Assig2.java file. You type itdirectly into that file; do not ask Eclipse to create a newclass for you or it will generate a second .java file which wedon't want right now. In other words, the file will look likethis:

import java.util.*;import java.lang.Math;public class Assig2{  // main class stuff ...} class ThreeString{  // ThreeString class stuff ...} 

As you see,ThreeString is to be definedafter, not within, theAssig2 class definition. This makes it a siblingclass, capable of being used by any other classes in the file (ofwhich there happens to be only one: Assig2).

After writing this class, test itusing a simple main() which instantiates anobject, mutates the members, displays the object, etc. Don't turnthis test in. It's part of your development cycle.

Answer & Explanation Solved by verified expert
4.3 Ratings (835 Votes)
import javautilpublic class Assig2 public static void mainString args TODO Autogenerated methodstubScanner scnew ScannerSysteminThreeString tRefnew ThreeString whiletrue SystemoutprintlnEnter the bet amount between 0 to 100int nscnextIntifn0 breakelse    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students