Results 1 to 3 of 3
  1. #1
    NBAPwns is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Unhappy True and False Help

    I have a True and False question program to do.
    What it's suppose to do is that there are 15 questions and are randomly chosen. (I used math.random)
    If the player gets the answer correct they get to roll (6 sided) and it's the next players turn.
    If the player gets it wrong they don't get to roll (6 sided) and it's the next players turn.


    What i did was i put all the questions and assigned them from 1 - 15 so that math.random can choose a question.

    My problem is how do i make it so that i can make if it's True they are able to roll and then it goes onto the next player and how if they get it false they don't roll and go to the next player.

    What i want it to do is ask a question randomly enter T or F and clear the screen so that if it's T they get to roll and the next player can answer
    Also when it's F it outputs that it's wrong and it would clear to another question and so on. Im new to this hoping for a fast reply im kind of stuck. this is what i have so far right now not finished yet

    Java Code:
        public static void TrueandFalse ()
        {
            char exit;
            char t = 0;
            char f = 0;
            int randomNumber = (int) (Math.random () * (15 - 1)) + 1;
            c.println ("Question Number: " + randomNumber);
    
            if (randomNumber == 1)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("When creating an if statement, you must use curly bracket marks if there is more than one statement in the if statement's body.");
                int p = Integer.parseInt (a);
                exit = c.getChar ();
                c.clear ();
    
            }
    
            else if
                (randomNumber == 2)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("Declarations can appear anywhere in the body of a Java method.");
                int q = Integer.parseInt (b);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if
                (randomNumber == 3)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("If you change the case of a String with a numerical value within it, an error is returned.");
                int three = Integer.parseInt (af);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if
                (randomNumber == 4)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("You are only able to use one type of loop in each main() method.");
                int four = Integer.parseInt (d);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if (randomNumber == 5)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("You are able to declare two of the same variable.");
                int five = Integer.parseInt (e);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if (randomNumber == 6)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("If an int value and a double value are added together, Java will automatically convert the double to an int.");
                int five = Integer.parseInt (e);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if (randomNumber == 7)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("It is not necessary to initialize local integer variables before using them because they will automatically contain a 0.");
                int seven = Integer.parseInt (g);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if (randomNumber == 8)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("Declarations must appear at the start of the body of a Java method .");
                int eight = Integer.parseInt (h);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if (randomNumber == 9)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("Declarations must appear at the start of the body of a Java method .");
                int eight = Integer.parseInt (h);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if (randomNumber == 10)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("The modulus operator (%) in Java can be used only with variables of integer type.");
                int nine = Integer.parseInt (i);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if (randomNumber == 11)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("The == operator can be used to compare two String objects. The result is always true if the two strings are identical.");
                int eleven = Integer.parseInt (k);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if (randomNumber == 12)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("A single Java arrays can hold data of different types.");
                int twelve = Integer.parseInt (l);
                exit = c.getChar ();
                c.clear ();
    
            }
    
    
            else if (randomNumber == 13)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("Unlike variables of the type int, float, double, and char, variables of the type String are artificial data types.");
                int thirteen = Integer.parseInt (m);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if (randomNumber == 14)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("Two methods cannot have the same name in Java.");
                int fourteen = Integer.parseInt (n);
                exit = c.getChar ();
                c.clear ();
            }
    
    
            else if (randomNumber == 15)
            {
                c.println ("TRUE OR FALSE?");
                c.println ();
                c.println ("You are not able to change variable values from a subclass.");
                int fifteen = Integer.parseInt (o);
                exit = c.getChar ();
                c.clear ();
            }
        }
    Last edited by NBAPwns; 12-19-2013 at 05:05 AM.

  2. #2
    NBAPwns is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Default Re: True and False Help

    What?! :s

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default Re: True and False Help

    if it's T they get to roll and the next player can answer
    Also when it's F it outputs that it's wrong and it would clear to another question
    Use an if statement to test if "it" is T or not
    If T roll and the next player can answer
    If F outputs that it's wrong and clear to another question

    There isn't enough code posted to see what the program does. There are many definitions for classes, methods and variables missing. The code looks like it using third party packages and classes, not standard Java SE classes.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. How Do I Change True False Statements
    By RSdroid in forum New To Java
    Replies: 5
    Last Post: 12-16-2013, 04:53 PM
  2. Check a list , true false
    By schvuu in forum New To Java
    Replies: 1
    Last Post: 10-17-2013, 11:11 PM
  3. how to balance true and false instances per id ?
    By aneuryzma in forum New To Java
    Replies: 1
    Last Post: 03-27-2011, 03:35 PM
  4. Prime Number - true , false
    By pinkdreammsss in forum Java Applets
    Replies: 11
    Last Post: 05-04-2010, 03:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •