use methods to calculate the probabilty of wining of rolling two dices

sevendays 2012-03-06 12:29:23
Calculate the probability of winning a pass bet in craps. Here are the rule for a pass bet. Roll two 6-sided dice, and let x be their sum.

if x is 7 or 11, you win instantly
if x is 2, 3, or 12, you lose instantly
otherwise, repeatedly roll two dice until their sum is either x or 7
if their sum is x, you win
if their sum is 7, you lose

Program dice.java takes user's input for N and simulates N pass bets. The program has two methods: sumOfTwoDice and winsPassBet. Both methods have one interesting feature - they do not take any input arguments. The first method simulate the throw of two dice. This returns an integer between 2 and 12, but not all values are equally likely. To simulate the probabilities correctly, we call random(6) twice and one to generate a number between 1 and 6. Then, we add the two values. The second method returns a boolean value: true if we win the pass bet and false otherwise. This method has several return statements. As soon as the first one is executed, the method terminates with the given return value.

The layout of your program is as shown below:

...全文
94 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

51,408

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧