/* CS 0401 - Jonathan Misurda This is our in-class demo program implementing the dice game of Craps. This is a comment in Java, or at least, one of the three styles of comments. Comments allow us to write documentation to the people reading and modifying our program. Comments should be used to discuss why a particular piece of code does what it does, rather than how it does it. The code says how, but any additional reasoning, issues that the code had to avoid, or just something non-obvious, should be explicitly stated in a comment near the code you are talking about. */ public class Craps { public static void main(String[] args) { //Phase one: roll two dice int roll1 = (int) (Math.random()*6) + 1; int roll2 = (int) (Math.random()*6) + 1; System.out.println("Roll was " + (roll1 + roll2)); int rollTotal = roll1 + roll2; //Did you lose? if(rollTotal == 2 || rollTotal == 3 || rollTotal == 12) { System.out.println("You lose!"); } //Did you win? else if(rollTotal==7 || rollTotal==11) { System.out.println("You win!"); } //Point phase else { System.out.println("Point is now " + rollTotal); int point = rollTotal; do { roll1 = (int)(Math.random()*6)+1; roll2 = (int)(Math.random()*6)+1; rollTotal = roll1 + roll2; System.out.println("You rolled " + rollTotal); } while(point != rollTotal && rollTotal != 7); if(rollTotal == 7) { System.out.println("You lose!"); } else { System.out.println("You win!"); } } } } /* The switch/case version is: switch(rollTotal) { case 2: case 3: case 12: System.out.println("You lose!"); break; case 7: case 11: System.out.println("You win!"); break; default: int point = rollTotal; System.out.println("Point is: " + rollTotal); do { roll1 = (int)(Math.random()*6) + 1; roll2 = (int)(Math.random()*6) + 1; rollTotal = roll1 + roll2; System.out.println("You rolled: " + rollTotal); } while(!(rollTotal == 7 || rollTotal == point)); if(rollTotal == 7) { System.out.println("You lose!"); } else { System.out.println("You win!"); } } */