# JAVA die

• 10-24-2003, 10:50 AM
russman0316
JAVA die
Me and a friend have been working on this for a while, and we can't get it . The program supposed to roll the dice(twice) and compare both scores..

Here's what we came up with:
Code:

```import javax.swing.*; import java.util.*; public class Dice { private Random random = new Random(); public int roll() { int die1 = random.nextInt(6) + 1; int die2 = random.nextInt(6) + 1; return die1 + die2; } public int[]tossResults(int number) { int[] result = {0,0,0,0,0,0,0,0,0,0,0,0,0}; for (int i=0; i<number; i++) result[roll()]++; return result; } public static void main(String [] args) { int userMoney; int numberOfRolls; int[] diceThrows; //int myDie1 = regularDie.getroll(); String input = JOptionPane.showInputDialog ("Enter the initial amount of money in dollars (no coins allowed)"); userMoney = Integer.parseInt(input); numberOfRolls=userMoney; for(int i=1; i<=userMoney; i--) { Dice dice = new Dice(); diceThrows = dice.tossResults(numberOfRolls); userMoney--; } if (die1==1 && die2==1) { userMoney++; JOptionPane.showMessageDialog(null, "You hit snake eyes, you won \$1, and your value now is \$"+userMoney); } if(die1==2 && die2==2) { userMoney+=2; JOptionPane.showMessageDialog(null, "You hit double two, you won \$2, and your value now is \$"+userMoney); } if(die1==3 && die2==3) { userMoney+=3; JOptionPane.showMessageDialog(null, "You hit double three, you won \$3, and your value now is \$"+userMoney); } if(die1==4 && die2==4) { userMoney+=4; JOptionPane.showMessageDialog(null, "You hit double four, you won \$4, and your value now is \$"+userMoney); } if(die1==5 && die2==5) { userMoney+=5; JOptionPane.showMessageDialog(null, "You hit double five, you won \$5, and your value now is \$"+userMoney); } if(die1==6 && die2==6) { userMoney+=6; JOptionPane.showMessageDialog(null, "You hit double six, you won \$6, and your value now is \$"+userMoney); } if (die2 < die1) userMoney-=die2; if (die2 > die1) userMoney-=die1; if (userMoney < 1) { JOptionPane.showMessageDialog(null, "You have lost all your money. Have a great day :)"); System.exit(0); } System.exit(0); } }```
I don't think we need array for this, do we? and how the heck do you get die1 and die1 into the public static void main(String [] args)? And it doesn't even roll :/

```class Dice {   /**   * Rolls a single dice.   * @return A number between 1 and 6.   */   public int roll(); }```