Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Game of Craps: won't compile

  1. #1
    Junior Member FreeBird's Avatar
    Join Date
    Feb 2010
    Location
    Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Game of Craps: won't compile

    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;
        }
        }
    Don't tell God how big your problems are.
    Tell your problems how big your GOD is!!


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Game of Craps: won't compile

    Why won't it compile? What are the compiler errors?...the compiler errors usually tell you enough to fix the these things quickly. Without going through all the code I can see at least one error in your rollDie method (where did the variable die come from)

  3. #3
    Junior Member FreeBird's Avatar
    Join Date
    Feb 2010
    Location
    Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Game of Craps: won't compile

    Quote Originally Posted by copeg View Post
    Why won't it compile? What are the compiler errors?...the compiler errors usually tell you enough to fix the these things quickly. Without going through all the code I can see at least one error in your rollDie method (where did the variable die come from)
    [code]
    the professor provided us with the code necessary to create a die class, which I have tested and does work. So in my program it calls the die from that class. The compile errors vary, eveything works fine from main to the rules, from there the program won't run.
    [code]
    Don't tell God how big your problems are.
    Tell your problems how big your GOD is!!

  4. #4
    Member
    Join Date
    Feb 2010
    Location
    Dehradun, India
    Posts
    37
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: Game of Craps: won't compile

    Where is your Die class??

  5. #5
    Junior Member FreeBird's Avatar
    Join Date
    Feb 2010
    Location
    Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Game of Craps: won't compile

     
    public class Die 
    {
     
            private final int MIN_NUMBER = 1;
            private final int MAX_NUMBER = 6;
            private final int NO_NUMBER = 0;
     
          int number;
     
            public Die()
            {
                number = NO_NUMBER;
            }
           public void roll()
            {
                number = (int) Math.floor(Math.random()*(MAX_NUMBER - MIN_NUMBER + 1)) +1;
            }
            public int getNumber()
            {   
                return number;
            }
     
        }
    here the die class for the above game of craps
    I don't know where to begin to get this program to work.
    any help would be appreciated
    thanks FreeBird
    Don't tell God how big your problems are.
    Tell your problems how big your GOD is!!

  6. #6
    Junior Member
    Join Date
    Feb 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Game of Craps: won't compile

    Any luck with this freebird. I'm having similar issues and I believe I'm writing the exact same program. I'm not sure where to go from here.

  7. #7
    Junior Member FreeBird's Avatar
    Join Date
    Feb 2010
    Location
    Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default no luckk yet

    [QUOTE]No luck yet, getting ready to try program using switch statements for various result.
    Are you a student at Depaul CDM? [\QUOTE]
    Don't tell God how big your problems are.
    Tell your problems how big your GOD is!!

  8. #8
    Junior Member
    Join Date
    Feb 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Game of Craps: won't compile

    Quote Originally Posted by gradstudent View Post
    Any luck with this freebird. I'm having similar issues and I believe I'm writing the exact same program. I'm not sure where to go from here.
    Yeah I have the class with Professor Gordon. I'm headed in to see a tudor to get some help.

  9. #9
    Junior Member FreeBird's Avatar
    Join Date
    Feb 2010
    Location
    Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Yea, professor Gordon as well

    I tried getting tutor help through Wimba, I don't like that program at all, very hard to hear or understand from the other end. Would you share any tips you get from the tutors even if it is too late, I would like to know how to make this program work. Thanks FreeBird[/QUOTE]
    Don't tell God how big your problems are.
    Tell your problems how big your GOD is!!

  10. #10
    Junior Member
    Join Date
    Feb 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Yea, professor Gordon as well

    Quote Originally Posted by FreeBird View Post
    I tried getting tutor help through Wimba, I don't like that program at all, very hard to hear or understand from the other end. Would you share any tips you get from the tutors even if it is too late, I would like to know how to make this program work. Thanks FreeBird
    [/QUOTE]

    Sure no problem!

Similar Threads

  1. Craps- GAME fine tunning.
    By Beaney in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 3rd, 2010, 08:32 PM
  2. Game 3x3
    By Koren3 in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 20th, 2009, 08:43 PM
  3. invisible box game
    By new2java in forum Loops & Control Statements
    Replies: 1
    Last Post: September 27th, 2009, 01:46 PM
  4. Job offers to program Hobo Wars
    By MooncakeZ in forum Paid Java Projects
    Replies: 7
    Last Post: September 17th, 2009, 10:41 PM
  5. [SOLVED] Fixing of bug for Pong game
    By phoenix in forum What's Wrong With My Code?
    Replies: 11
    Last Post: July 14th, 2009, 02:19 PM

Tags for this Thread