java怎么写掷骰子_java程序请教,掷骰子

//Craps.java//CrapsClasssimulatesthedicegamecrapsimportjava.util.RandompublicclassCraps{//createrandomnumbergeneratorforuseinmethodrollDice

//Craps.java//CrapsClasssimulatesthedicegamecrapsimportjava.util.RandompublicclassCraps{//createrandomnumbergeneratorforuseinmethodrollDiceprivateenumStatus{CONTINUE,WON,LOST};//contantsthatrepresentcommonrollsofthediceprivatefinalstaticintSNAKE_EYES=2;privatefinalstaticintTREY=3;privatefinalstaticintSEVEN=7;privatefinalstaticintYO_LEVEN=11;privatefinalstaticintBOX_CARS=12;//playonegameofcrapspublicvoidplay(){intmyPoint=0;statusgameStatus;intsumOfDice=rolldice();//firstrollofthedice//determinegamestatusandpointbasedonfirstrollswitch(sumOfDice){:gameStatues=Status.WON;break;caseSNAKE_:caseBOX_:gameStatues=Statues.CONTINUE;myPoint=sumOfDice; intf("pointis%d\n",point);break;}//whilegameisnotcompletewhile(gameStatues==Statues.CONTINUE){sumOfDice=rollDice();//rolldiceagain//determinegamestatusif(sumOfDice==myPoint)gameStatus=status.WON;elseif(sumOfDice==SEVEN)gameStatus=Status.LOST;}//endwhile//displywonorlostmessageif(gameStatues==Status.WON) intln("playerwon");else intln("playerlost");}//endmethodplay//rolldice,calculatesumanddisplayresultspublicintrollDice(){//pickrandomdievaluesintdie1=1+ xtInt(6);intdie2=1+ xtInt(6);intsum=die1+die2; intf("Playerrolled%d+%d=%d\n",die1,die2,sum);returnsum;}//endmethodrollDice}//endClassCraps//Fig.6.10:CrapsTest.java//ApplicationtotestclassCraps.publicclassCrapsTest{publicstaticvoidmain(Stringargs[]){Crapsgame=newCraps(); ay();}//endmain}endclassCrapsTest怎么改才能当程序运行完后问用户是否再玩一遍,当用户输入Y是再运行一遍然后把结果存入一个数组,最后打印一个总结例子:SummaryofGame(s):4 :Lost….

展开

全部

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值