importjava.util.Random;publicclassGambler{staticintbet;/* Amount of current bet on the table */staticintmoney;/* Amount of money in pocket */staticintinitial;/* Amount of money I started out with */staticRandomgenerator;staticbooleanisGambling;/* Whether or not I am gambling */publicGambler(intm){initial=money=m;generator=newRandom();isGambling=true;say("I have $"+money+" and I'm ready to gamble.");Random();}publicvoidSmart(){/* Know when to quit */doublepercentbet=1.0/8.0;// Percentage of spendable money to betintstore=money/2;// Amount to not gamble withwhile(isGambling){bet=(int)(((double)(money-store))*percentbet);if(bet==0)bet++;say("\tSaving $"+store+"");if(money<=store){quit();break;}gamble();store=Math.max(store,money/2);// Store can only go upif(money>=initial+(money-store))store=Math.max(store,initial);// Hurrah}}publicvoidReallySmart(){quit();}publicvoidHalf(){while(isGambling){bet=money/2;if(bet==0){quit();break;}gamble();}}publicvoidHalfWithStore(){doublecollection=9.0/10.0;intstore=(int)(((double)money)*collection);while(isGambling){bet=(int)(((double)(money-store))*(1.0-collection));if(money<=store){quit();break;}gamble();if(money>=initial*2)store=(int)(((double)money)*collection);}}publicvoidRandom(){while(isGambling){bet=generator.nextInt(money);gamble();if(money<=1){quit();}}}publicvoidMartingale(){/* Double bet after loss; Half after win */bet=1;booleanwin;while(isGambling){win=gamble();if(win){bet=bet/2;if(bet==0)bet=1;}elsebet=bet*2;}}publicvoidMartingaleInverse(){/* Double bet after win; Half after loss */bet=1;booleanwin;while(isGambling){win=!gamble();if(win){bet=bet/2;if(bet==0)bet=1;}elsebet=bet*2;}}publicbooleangamble(){booleanwin=generator.nextBoolean();if(win){money=money+bet;say("I won $"+bet+"! ($"+money+")");}else{money=money-bet;say("I lost $"+bet+"! ($"+money+")");if(money<0){goBankrupt();}}returnwin;}publicvoidquit(){intdiff=money-initial;say("I am done gambling! I leave with $"+money+"!");if(diff>0){say("In the end, I gained $"+diff+"!");}elseif(diff<0){say("In the end, I lost $"+Math.abs(diff)+"!");}else{say("In the end, I left with what I came with.");}isGambling=false;}publicvoidgoBankrupt(){say("I am bankrupt!");quit();}publicvoidsay(Stringmsg){System.out.println(msg);}}