import java.util.*; import java.io.*; public class playGame { //This is main method of the class public void main(String[] args) { boolean Y = true; Scanner console = new Scanner(System.in); System.out.println("Hi there! Do you want to play some craps? (Y || N)"); console.next(); if (!Y) System.exit(0); else { System.out.println("Do you want to read the rules of the game? (Y || N)"); console.next(); } { if (!Y) System.exit(0); else {// rules of the game System.out.print("The program is to play the game of dice called craps.\n" +"The term comes from the French term 'crab', which \n" + "means to \"lose the throw\"" + ".\n" +"A dice is a six-sided cube with a number of spots on it \n" +"The number of spots range from 1 to 6, inclusive. \n" +"The rules are as follows: two die are thrown and the \n" + "sum of their two faces are added up, giving a number from \n" + "2 to 12. If the number is 7 or 11, the thrower wins. If \n" + "the number is 2, 3, or 12, the thrower loses. If is is \n" + "neither of these numbers (i.e., it is either 4, 5, 6, 8, or \n" + "9, or 10), this number becomes the point. The thrower \n" + "continues to throw the dice until either his point comes \n" + "up or the number 7 comes up. If the point comes up, the \n" + "thrower wins. If a 7 comes up, the thrower loses. (One \n" + "says he \"crapped out\"" + "). If the thrower wins, he plays \n" + "again. If he loses, he gives up the dice to the next player.\n" + "(Hence, the term \"crapped out\"" + " or lose the throw.\n "); } } System.exit(0); } //method play public int play(int num) { //create two new objects of the classDie Die dieOne = new Die(); Die dieTwo = new Die(); int result; int points; int rollcount= 0; //code for calling private method rollDie result = rollDie(dieOne, dieTwo); if ((result ==7) || (result == 12)) { System.out.println("The die came to " + result + "you have won the game!"); System.exit(0); } if ((result ==3) || (result ==11)) System.out.println("They die came to " + result + "you lost."); System.exit(0); //continues rolling die and totalling points until win or lose occurrs. do { System.out.println("You're total points are "+ points + "."); //calls private method rolldie result = rolldie(Die one,Die two); points = dieOne + dieTwo; System.out.println("Your total points are now " + points + "."); rollcount ++; } while (result != 7 || 12 || 3 || 11); return rollCount; } //private method rollDie private int rollDie(Die one, Die two) { one.roll(); two.roll(); return die; } }