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 3 of 3

Thread: Help me

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help me

    I have this code, but I keep getting compiling errors. Can someone help me?

    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(dieOne,dieTwo);
                    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;
        }
        }

    This was the die class we were given.

    /**
     * Write a description of class Die here.
     * 
     * @author Gerald Gordon
     * @version March 15, 2004
     */
    public class Die
    {
        //The smallest number a die can have
        private final int MIN_NUMBER = 1;
        //The largest number a die can have
        private final int MAX_NUMBER = 6;
        //The initialization of the die when created
        private final int NO_NUMBER = 0;
     
        //the current value of the die
        int number;
     
        public Die()
        {
            number = NO_NUMBER;   
        }
     
        //this procedure rolls the die
        public void roll()
        {
             number = (int) Math.floor(Math.random()*(MAX_NUMBER - MIN_NUMBER + 1)) +1;
        }   
     
        public int getNumber()
        {
            return number;   
        }
     
    }
    Last edited by helloworld922; May 7th, 2010 at 03:56 PM. Reason: Please use [code] tags

  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Help me

    what's the error message you are getting?

  3. #3
    Junior Member
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help me

    operate + cannot be applied to Die,Die as well as some other ones.