Beetle game..trouble with a method?

I finally got the game to work (somewhat). The player keeps collecting body parts until it switches turns, then computer collects parts. However when one of the players (comp or player) gets a full beetle it still rolls...is my logic in these two methods correct?
public static void playBeetle(String playerName, boolean hasBody, boolean hasHead,
            int legCount, int eyeCount, int feelerCount, boolean hasTail)
        boolean playerBody = false, computerBody = false, body=false,
                playerHead = false, computerHead = false, head=false,
                playerTail = false, computerTail = false, tail=false;
        int     playerLegs = 0,     computerLegs = 0,     legs=0,
                playerEyes = 0,     computerEyes = 0,     eyes=0,
                playerFeelers = 0,  computerFeelers = 0,  feelers=0;
        boolean winner = false;
        boolean rollAgain = true;
        boolean playerTurn = true;
        String message = "";
        int roll=0;
        String bodyPart = "";
        while(!winner)
            //Sets thr generic parts into the players parts depending on who's turn it is.
            if(playerTurn)
                body=playerBody;
                head=playerHead;
                tail=playerTail;
                legs=playerLegs;
                eyes=playerEyes;
                feelers=playerFeelers;      
            else
                body=computerBody;
                head=computerHead;
                tail=computerTail;
                eyes=computerEyes;
                feelers=computerFeelers;
                legs=computerLegs; 
            while(rollAgain)
                 if(playerTurn)
                        message+="\n"+playerName+":\n";
                    else
                        message+="\nCOMPUTER: \n";
                message+=beetleString(body, head, legs, eyes, feelers, tail)+"\n";          
                roll=randomGenerator.nextInt(6)+1;
                message+="\nDie roll:"+roll+"...>";
                switch(roll)
                    case BODY:
                         bodyPart="body";
                         if(body)
                            rollAgain=false;
                         else
                            body=true;
                    break;
                    case HEAD:
                        bodyPart="head";
                        if(body)
                            if(head)
                                rollAgain=false;
                            else
                                head=true;
                        else
                            rollAgain=false;
                    break;
                    case LEG:
                        bodyPart="two legs";
                        if(body)
                            if(legs==6)
                                rollAgain=false;
                            else
                                legs=legs+2;
                        else
                            rollAgain=false;
                    break;
                    case EYE:
                        bodyPart="eye";
                        if(head)
                            if(eyes==2)
                                rollAgain=false;
                            else
                                eyes=eyes+1;
                        else
                            rollAgain=false;
                    break;
                    case FEELER:
                        bodyPart="feeler";
                        if(head)
                            if(feelers==2)
                                rollAgain=false;
                            else
                                feelers=feelers+1;
                        else
                            rollAgain=false;
                    break;
                    case TAIL:
                        bodyPart="tail";
                        if(body)
                            if(tail)
                                rollAgain=false;
                            else
                                tail=true;
                        else
                            rollAgain=false;
                message+=bodyPart;
                if(rollAgain)
                     message+=beetleString(body, head, legs, eyes, feelers, tail);
                     if(completeBeetle(body, head, tail, legs, eyes, feelers))
                       if(playerTurn)
                           message+="\n Congratulations! You won!";
                       else
                           message+="\n Computer Won! Better luck next time!";
                       rollAgain=false;
                       winner=true;
                    else
                        message+="\n Click O.K. to roll again.";
                else
                    message+="\nSorry, you cannot use the "+bodyPart;
                JOptionPane.showMessageDialog(null, message);
                message="";
           rollAgain=true;
           //Assigns players parts back to generic parts.
           if(playerTurn)
               playerBody=body;
               playerHead=head;
               playerTail=tail;
               playerLegs=legs;
               playerEyes=eyes;
               playerFeelers=feelers;
           else
               computerBody=body;
               computerHead=head;
               computerTail=tail;
               computerLegs=legs;
               computerEyes=eyes;
               computerFeelers=feelers;
           playerTurn=!playerTurn;
    }  // end method playBeetle
public static boolean completeBeetle(boolean body, boolean head, boolean tail, int legs,
                        int eyes, int feelers)
        boolean fullBeetle=false;
        if(body)
            if(head)
                if(tail)
                    if(legs==6)
                        if(eyes==2)
                            if(feelers==2)
                                fullBeetle=true;
        return false;
    } // end method completeBeetle

Your original code was fine, you only needed to change one thing...
public static boolean completeBeetle(boolean body, boolean head, boolean tail, int legs,
                        int eyes, int feelers)
        boolean fullBeetle=false; //<-- this way you would need this
        if(body)
            if(head)
                if(tail)
                    if(legs==6)
                        if(eyes==2)
                            if(feelers==2)
                                fullBeetle=true; // <-- here should be...
                                return true;
        return false;
    } // end method completeBeetleLogically...
You only need to return true or false, so...
if all your ifs prove true (the case you want) just return true...
if not all if are met the method will hit the return false...
this is because the compiler "kicks out of the method" when it sees a return statement, but...
this way you also must capture the result of the method call! Hope that helps!

Similar Messages

  • TROUBLE WITH PAYMENT METHOD USED DIFFRENT VISA PAYMENTS STILL WONT WORK

    TROUBLE WITH PAYMENT METHOD USED DIFFRENT VISA PAYMENTS STILL WONT WORK

    This is a case for the iTunes Store Support:
    1. Go to expresslane.apple.com
    2. select 'itunes' and then 'itunes store' on the right
    3. select a topic and a subject
    4. click 'continue' and then 'email'
    5. fill out the form and explain your situation
    6. they will respond within 24 hours usually
    Good luck
    Stijn

  • Trouble with forward() method in a Servlet

    I am new to Servlets and am having trouble with one that queries a database and forwards the data to a JSP. A portion of the code is below (The <i> are really , but are being displayed wrong).
                   for(int i = 0; i < numberOfRows; i++)
                        data2[0] = rs.getString("REIMBUR_DATE");
                        data2[i][1] = occupancyPCT;
                        data2[i][2] = rs.getString("RMBR_RATE_REVENUE");
                        data2[i][3] = rs.getString("RMBR_ROOM_TAX");
                        data2[i][4] = "reimbur total";
                        data2[i][5] = rs.getString("BOOK_RATE_REVENUE");
                        data2[i][6] = rs.getString("BOOK_ROOM_TAX");
                        data2[i][7] = "rebate";
                        data2[i][8] = "tax rebate";
                        rs.next();
                   request.setAttribute("CERT_INFO", data);
                   request.setAttribute("OTHER_INFO", data2);
                   request.setAttribute("NUMBER_ROWS", new Integer(numberOfRows));
                   ServletContext context = getServletContext();
                   RequestDispatcher dispatcher = context.getRequestDispatcher("/certdetails.jsp");
                   dispatcher.forward(request, response);
              catch(Exception ee)
                   PrintWriter out = null;
                   response.setContentType("text/html");
                   out = response.getWriter();
                   out.println("<html>");
                   out.println("<body>");
                   out.println("Exception !!<br>");
                   out.println(ee.getMessage());
                   out.println("</body>");
                   out.println("</html>");
    When I include the line with the forward() method, I get an exception and the message is "1998-08-20", the contents of data2[numberOfRows - 1][0]. I don't know why an exception is being generated or how it is getting this database value as its message. What's going on?

    Nevermind, I found the problem. There was an error in my JSP. I don't know how it affected the Servlet as it did, but...who cares!!

  • Having trouble with "main" method

    I have just installed j2re1.4.1 and I am having trouble running my applications. Every time I try to run even the smallest of apps I get an error message about the "Main" method.
    In textpad i get this message:
    "Exception in thread "main" java.lang.NoClassDefFoundError:"
    and in Jcreator I get this message:
    "The system couldnt find a suitable main method"
    what is going wrong?How can I fix this?

    It could be something as simple as Case :-/
    If you have a file Foo.java with a class Foo with a main()
    you can compile it with javac foo.javawhich will create Foo.classbut you cannot run it with java fooyou will get Exception in thread "main" java.lang.NoClassDefFoundError: roids (wrong name: Foo)whereas java Foowill work just fine.

  • Some trouble with getElementById method

    Hi
    I have an XML file just like that:
    <?xml version="1.0" encoding="UTF-8"?>
    <persons id="root">
        <firstname1 id="firstname1">John</firstname1>
        <lastname1 id="lastname1">Brown</lastname1>
        <firstname2 id="firstname2">Andrew</firstname2>
        <lastname2 id="lastname2">Clark</lastname2>
        <firstname3 id="firstname3">Sylvie</firstname3>
        <lastname3 id="lastname3">Steevens</lastname3>
        <firstname4 id="lastname3"></firstname4>
        <lastname4 id="lastname4"></lastname4>
    </persons>I enter this one into the Document by using the standard way, problem is with calling gsome etElementById method. When I put there any one id value, firstname1, or root for instance, then I get null.
    What do I do wrong?
    Regards
    Krzysztof Malinowski

    http://javaalmanac.com/egs/org.w3c.dom/GetById.html

  • Trouble with isDigit method

    Hi guys,
    I am currently in the middle of my first Assignment for an intro to java. I seem to have done alright so far, except just for a couple of minor details. Firstly, I am developing an EXTREMELY basic atm prototype. I am passing the staring balance as a HTML parameter. I wan't to check that is is all numeric. If not then I want the label that displays the updated balance to say something like "must enter valid dollar amount". I know I have to use the isDigit method, 'cause I have successfully done that for my textfield, but I have absolutely no idea how to do it for this. I shall paste the relevant sections of code (that apear in order) and hope someone can help :)
    public void init()
         {//start of init method - initialisation of the applet
              //assigning inital balance to current balance variable
              StartBalStr = this.getParameter("InitialBalParameter");
              if ((StartBalStr == null) || (StartBalStr.equals("")))
                   StartBalStr = "No Starting Balance Provided";
    public static boolean isStringAllNumeric(String aString)
         {//looping structure to check from the first character to the last of the value entered
              int stringSize = aString.length();
              for (int i = 0; i < stringSize; i++)
                   boolean check = Character.isDigit(aString.charAt(i));
                   if (!check)
                   return false;//if any characters at each position of the string's length is not a digit
                        return true;//if any characters at each position of the string's length is a digit
         }//end of isStringAllNumeric function     
    public void keyTyped(KeyEvent ke)
                   char c = ke.getKeyChar();
                   if (!((Character.isDigit(c)) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) || (c == '.')))
                        getToolkit().beep();
                        ke.consume();

    How about this....
    if (isStringAllNumeric(StartBalStr)) {
    System.out.println("The param is numeric");
    } else {
    System.out.println("The param is non-numeric");
    Hope that was what you were after.
    Alan

  • Hi i am havin trouble with my ipad after i have downloaded a game and have been playing for a while it seems to of diapeared and the screen goes a white blank background there is nothing on the screen at all so i switch it off and back on and it is white

    hi i am having trouble with games on my ipad as i have been playing them the screen goes white and i can't play the game i go back to the game centre on the ipad and click on the icon for the game and come up to play i push play buton and the screen come up again white so any body had the same problem could they let me no thanks

    Quit the game and restart the iPad.
    To quit the game - Go to the home screen first by tapping the home button. Quit/close open apps by double tapping the home button and the task bar will appear with all of you recent/open apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus sign in the upper left corner to close the apps. Restart the iPad. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    If that doesn't work try this.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.

  • Trouble with a If conditional using string methods.

    Hello Everyone,
    I am having trouble with an If statement. I want to compare a string variable to two values using the or operator. I have found the || may not be applied to string.equals. Would neone happen to have a different method? Code below:
    check = ("C".equals(option)) || ("F".Equals(option));

    jverd wrote:
    Please paste in the exact, complete error message.
    One thing that's definitely wrong is the capital E in your second Equals. I don't know if that's causing the problem though.Also note that, once you get it to compile, if you don't remove the semicolon after the if statement, you won't get the behavior you want.

  • I'm having trouble with the purchase of currency in the game Castle Clash locks! In order status says "Back" returns so what? Money at stake so I have not returned!

    I'm having trouble with the purchase of currency in the game Casyle Clash locks! In order status says "Back" returns so what? Money at stake so I have not returned!

    You need to contact the developer of the game, or, the iTunes store support.  iTunes store "MIGHT" issue a 1 time refund.  If you want the credits for the game, talk to the game creator.

  • I'm having trouble with the audio on a lot of my games. How can that be fixed?

    I'm having trouble with the audio on a lot of my games. How can that be fixed?

    You need to be more specific. What sort of trouble - no audio, low volume, scratchy sound, etc.?
     Cheers, Tom

  • I am having trouble with my candy crush saga game. It will not allow me to purchase more lives. The finances are fine. What do I do to get it to allow me to purchase more lives?

    I am having trouble with my candy crush saga game. I am not being allowed to purchase more lives, even though the finances are ok.

    Aha! I have sorted it.
    For those with similar problems, the solution is this:
    Macintosh HD > Library > Audio > MIDI Drivers
    Then delete DigiDioMidiDriver.plugin

  • I play pogo gams and they are not loading im always having trouble with firefox

    every time i try to play my pogo games the games are not loading and i keep losing my interent connection. why do i always have trouble with firefox this is getting very annoying
    since i pay to play pogo games

    how can this be fixed

  • Hi I'm having trouble with your purchase of the game clash of clans

    I'm having trouble with your purchase of the game clash of clans

    Knowing I purchased approximately 4 days before the Master Carr knowing that MasterCard is charged and there is balance I want a solution to my problem

  • Trouble with game center

    I'm having trouble with game center, it ask me to login and when I put the password it says that I don't have an account in it, what should I do ?

    Uh? Thanks.

  • Beetle game...stuck!

    Im trying to get the dialog box in the playBeetle method to display the number rolled and a body (if a one is rolled) or the message"that part cant be used" and if the player can use the part they roll again however if they cannot its the computers turn.
    //******************* IMPORT STATEMENTS ************************************
    import javax.swing.*;
    import java.util.Random;
    /** Class BeetleGame: The object of the Beetle game is to be the first player
    * to complete a beetle. Players earn parts of the beetle by throwing a die.
    * There is one player who plays against the computer.
    * The player can play multiple games. The program does not end until the
    * player indicates that he/she does not wish to play again.
    * Here is a picture of a complete beetle and the numbers a player needs to
    * roll to earn a body part:
    *   \ /        1. body
    *   o0o        2. head
    *  --*--       3. two legs
    *  --*--       4. one eye
    *  --*--       5. one feeler
    *    v         6. tail
    * See the method: displayRules to see the complete rules for the game.
    public class BeetleGame
        public static final int BODY = 1,
                                HEAD = 2,
                                LEG = 3,
                                EYE = 4,
                                FEELER = 5,
                                TAIL = 6;
        public static Random randomGenerator = new Random();
        //************* MAIN METHOD ********************************************
        public static void main(String[] args)
            boolean playAgain=false;
            boolean hasHead=false;
            boolean hasBody=false;
            boolean hasTail=false;
            boolean hasFeelers=false;
            boolean hasEyes=false;
            boolean hasLegs=false;
            int feelerCount=0;
            int eyeCount=0;
            int legCount=0;
            String playerName=beetleGameIntro();
            while(playAgain=true)
               playBeetle(playerName, hasBody, hasHead,
                legCount, eyeCount, feelerCount, hasTail);
            System.exit(0);
        } // end main
         * Controls the total play for one complete game of Beetle.
         * @param playerName is the name of the player who will play against the
         *                   computer.
        public static void playBeetle(String playerName, boolean hasBody, boolean hasHead,
                int legCount, int eyeCount, int feelerCount, boolean hasTail)
            boolean playerBody = false, computerBody = false, body=false,
                    playerHead = false, computerHead = false, head=false,
                    playerTail = false, computerTail = false, tail=false;
            int     playerLegs = 0,     computerLegs = 0,     legs=0,
                    playerEyes = 0,     computerEyes = 0,     eyes=0,
                    playerFeelers = 0,  computerFeelers = 0,  feelers=0;
            boolean winner = false;
            boolean rollAgain = true;
            boolean playerTurn = true;
            String message = "";
            int roll=0;
            String bodyPart = "";
            while(rollAgain)
                roll=randomGenerator.nextInt(6)+1;
                JOptionPane.showMessageDialog(null, playerName+": \n"+beetleString(hasBody, hasHead,
                                   legCount, eyeCount, feelerCount, hasTail)+"\n\n Die roll: "+roll
                                   +" ..>"+bodyPart);
                   switch(roll)
                       case 1:
                           bodyPart=" body";
                           if(body)
                               message="Sorry, you cannot use the body";
                               rollAgain=false;
                            else
                                body=true;
                        case 2:
                            if(body)
                                if(head)
                                    message="Sorry, you cannot use the head";
                                    rollAgain=false;
                                else
                                    bodyPart=" head";
                                    head=true;
                            else
                                message="Sorry, you cannot use the head";
                                rollAgain=false;
                        case 3:
                            if(body)
                                if(legs==6)
                                    message="Sorry, you cannot use the legs";
                                    rollAgain=false;
                                else
                                    bodyPart=" two legs";
                                    legs=legs+2;
                            else
                                message="Sorry, you cannot use the legs";
                                rollAgain=false;
                        case 4:
                            if(head)
                                if(eyes==2)
                                    message="Sorry, you cannot use the eyes";
                                    rollAgain=false;
                                else
                                    bodyPart=" one eye";
                                    eyes=eyes+1;
                            else
                                message="Sorry, you cannot use the eyes";
                                rollAgain=false;
                        case 5:
                            if(head)
                                if(feelers==2)
                                    message="Sorry, you cannot use the feelers";
                                    rollAgain=false;
                                else
                                    bodyPart=" one feeler";
                                    feelers=feelers+1;
                            else
                                message="Sorry, you cannot use the feelers";
                                rollAgain=false;
                        case 6:
                            if(body)
                                if(tail)
                                    message="Sorry, you cannot use the tail";
                                    rollAgain=false;
                                else
                                    bodyPart=" tail";
                                    tail=true;
                            else
                                message="Sorry, you cannot use the tail";
                                rollAgain=false;
            while(!winner)
                if(playerTurn)
                else
                playerTurn=!playerTurn;
        }  // end method playBeetle
         * Determines if the body parts indicated by the values passed to the
         * parameters make up a complete beetle.
         * @param body is true if this beetle has a body, false if it does not
         * @param head is true if this beetle has a head, false if it does not
         * @param legs the number of legs this beetle has.
         *             Must be 0, 2, 4, or 6.
         * @param eyes the number of eyes this beetle has. Must be 0, 1, or 2.
         * @param feelers the number of feelers this beetle has.
         *                Must be 0, 1, or 2.
         * @param tail is true if this beetle has a tail, false if it does not
         * @return true if this beetle has a body, head, tail, 2 eyes,
         *              2 feelers, and 6 legs, returns false otherwise.
        public static boolean completeBeetle(boolean body, boolean head, boolean tail, int legs,
                            int eyes, int feelers)
            return false;
        } // end method completeBeetle
         * Builds a String that contains only the body parts that this beetle
         * has as indicated by the values passed to the parameters. The string
         * includes new lines needed such that the string when printed will
         * display a appropriately formatted beetle.If the beetle has no body
         * parts the string returned will be "No parts yet.\n".
         * @param body is true if this beetle has a body, false if it does not
         * @param head is true if this beetle has a head, false if it does not
         * @param legs the number of legs this beetle has.
         *             Must be 0, 2, 4, or 6.
         * @param eyes the number of eyes this beetle has. Must be 0, 1, or 2.
         * @param feelers the number of feelers this beetle has.
         *                Must be 0, 1, or 2.
         * @param tail is true if this beetle has a tail, false if it does not
         * @return
        public static String beetleString(boolean body, boolean head,
                                   int legs, int eyes, int feelers,
                                   boolean tail)
                String feelerAnswer="" ;
                String eyeAnswer="";
                String legAnswer="";
                String tailAnswer="";
                if(body==true)
                    if(head==true)
                        if(feelers==2)
                            feelerAnswer="  \\ /";
                        else if(feelers==1)
                            feelerAnswer="  \\ ";
                        else if(feelers==0)
                            feelerAnswer="";
                        if(eyes==2)
                            eyeAnswer=" o0o  ";
                        else if(eyes==1)
                            eyeAnswer="  o0   ";
                        else if(eyes==0)
                            eyeAnswer="   0   ";
                        if(legs==6)
                            legAnswer="--#--\n--#--\n--#--";
                        else if(legs==4)
                            legAnswer="  #  \n--#--\n--#--";
                        else if(legs==2)
                            legAnswer="  #  \n  #  \n--#--";
                        else if(legs==0)
                            legAnswer="  #  \n  #  \n  #  ";
                        if(tail==true)
                            tailAnswer="  v  ";
                        return feelerAnswer+"\n"+eyeAnswer+"\n"+legAnswer+"\n"+tailAnswer;
                return "No parts yet.";
        } // end method beetleString
         * Displays a greeting, gets the player's name, and displays the rules
         * if the player wants to see them.
         * @return the player's name as input by the player.
        public static String beetleGameIntro()
            boolean seeRules;
            String playerName;
            playerName=JOptionPane.showInputDialog("Welcome to the Beetle Game! "+
                                                   "\n \n What is your name? ");
            seeRules=yes("HELLO "+playerName+".\n\n Would you like to see the rules (Y/N)?");
            if(seeRules)
                displayRules();
            return playerName;
        } // end method beetleGameIntro
         * Displays the rules for the Beetle game.
        public static void displayRules()
            String rules = "Beetle Game\n\n"
                + "Players: 2 - you and the computer.\n\n"
                + "Object: To be the first player with a complete beetle.\n"
                + "        A complete beetle has a body, a head, six legs,\n"
                + "        two eyes, two feelers, and a tail.\n\n"
                + "Setup: Each player starts with no parts on his/her beetle."
                + "\n\n"
                + "Play: On your turn, roll a die, and act on the result:\n"
                + "   1. If your beetle already has a body, pass the die to"
                + "      the next player.\nOtherwise, add a body and roll"
                + " again.\n\n"
                + "   2. If your beetle already has a head or has no body, \n"
                + "      pass the die to the next player.\n "
                + "      Otherwise, add a head and roll again.\n\n"
                + "   3. If your beetle already has six legs or has no body,\n"
                + "      pass the die to the next player.\n"
                + "      Otherwise, add two legs and roll again.\n\n"
                + "   4. If your beetle already has two eyes or has no head,\n"
                + "      pass the die to the next player.\n"
                + "      Otherwise, add an eye and roll again.\n\n"
                + "   5. If your beetle already has two feelers or has no head"
                + ",\n      pass the die to the next player.\n"
                + "      Otherwise, add a feeler and roll again.\n\n"
                + "   6. If your beetle already has a tail or has no body,\n"
                + "      pass the die to the next player.\n"
                + "      Otherwise, add a tail and roll again.";
                JOptionPane.showMessageDialog(null, rules);
            } // end method displayRules
         * Uses a dialog box to ask the yesOrNoQuestion and converts the users
         * String response to the corresponding boolean value.
         * @param yesOrNoQuestion is the question to be asked of the user.
         * @return true if the user gives any response that begins with the
         *         letter 'y' (after skipping white space) in either upper or
         *         lower case or returns false for any other response.
        public static boolean yes(String yesOrNoQuestion)
            boolean yes = false;
            String response = JOptionPane.showInputDialog(yesOrNoQuestion);
            if(response != null)
                response = response.trim().toUpperCase();
                yes = response.charAt(0) == 'Y';
            return yes;
        } // end method yes
    } // end class BeetleGame

    Ok so i fixed the switch statement now the dialog box is correct but now i want to know how to switch to the computers turn after rollAgain ia set to false...
    while(rollAgain)
                roll=randomGenerator.nextInt(6)+1;
                   switch(roll)
                       case 1:
                           bodyPart=" body";
                           if(body)
                               message="Sorry, you cannot use the body";
                               rollAgain=false;
                            else
                                body=true;
                        break;
                        case 2:
                            bodyPart=" head";
                            if(body)
                                if(head)
                                    message="Sorry, you cannot use the head";
                                    rollAgain=false;
                                else
                                    head=true;
                            else
                                message="Sorry, you cannot use the head";
                                rollAgain=false;
                        break;
                        case 3:
                            bodyPart=" two legs";
                            if(body)
                                if(legs==6)
                                    message="Sorry, you cannot use the legs";
                                    rollAgain=false;
                                else
                                    legs=legs+2;
                            else
                                message="Sorry, you cannot use the legs";
                                rollAgain=false;
                        break;
                        case 4:
                            bodyPart=" one eye";
                            if(head)
                                if(eyes==2)
                                    message="Sorry, you cannot use the eyes";
                                    rollAgain=false;
                                else
                                    eyes=eyes+1;
                            else
                                message="Sorry, you cannot use the eyes";
                                rollAgain=false;
                        break;
                        case 5:
                            bodyPart=" one feeler";
                            if(head)
                                if(feelers==2)
                                    message="Sorry, you cannot use the feelers";
                                    rollAgain=false;
                                else
                                    feelers=feelers+1;
                            else
                                message="Sorry, you cannot use the feelers";
                                rollAgain=false;
                        break;
                        case 6:
                            bodyPart=" tail";
                            if(body)
                                if(tail)
                                    message="Sorry, you cannot use the tail";
                                    rollAgain=false;
                                else
                                    tail=true;
                            else
                                message="Sorry, you cannot use the tail";
                                rollAgain=false;
                    JOptionPane.showMessageDialog(null, playerName+": \n"+beetleString(hasBody, hasHead,
                                   legCount, eyeCount, feelerCount, hasTail)+"\n\n Die roll: "+roll
                                   +" ..>"+bodyPart+"\n"+message);     
                        

Maybe you are looking for