This site requires JavaScript, please enable it in your browser!
Greenfoot back
cobarr
cobarr wrote ...

2014/5/25

Display question generated to a String

cobarr cobarr

2014/5/25

#
How do I make the the string of numbers as a question show up in my game? I want to make the question show up in my game via the level1 method in MathWorld. Act method in my Question class:
   public void act() 
    {
        System.out.println(String.format("%d %s %d", this.left, this.op.mnemonic,this.right));

    }   
Isn't this already printing the question? ----------------------------------------- How do I code "if the user is on level1 method in my MathWorld, get random numbers for this.left under 10 and this.right under 10?"
public void Question(int level)
    {
        MathWorld mw = (MathWorld) getWorld(); 
        
        this.op = ops[Greenfoot.getRandomNumber(numOps)];
        this.left = Greenfoot.getRandomNumber(10);
        this.right = Greenfoot.getRandomNumber(10);
    }
danpost danpost

2014/5/25

#
First off, you need to put a condition on displaying the question (you do not want the question to be repeatedly displayed on the terminal). Second, you need to call the 'Question' method to load the new values before displaying the question. FYI, you cannot create terminal output using System.out.println on the site.
You need to login to post a reply.