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

2019/5/15

My Code Doesnt work

hassan08 hassan08

2019/5/15

#
import greenfoot. *; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class questions here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class asks extends Actor
{
    /**
     * Act - do whatever the questions wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
        int a = Greenfoot.getRandomNumber(10);
        int b = Greenfoot.getRandomNumber(10);
        int result = a + b;
        int answer = Integer.parseInt(Greenfoot.ask("How much is " + a + " + " + b + "?"));
        
        if (result == answer)
        {
            Message messagebox = new Message("Well Done You Go to The next LEVEl!!!!");

        }
        else
        {
            Message messagebox = new Message("You Failed!! Try Again!");
        }
    }    
}
Super_Hippo Super_Hippo

2019/5/15

#
I am not gonna list all possible problems with this code. You should describe what your problem is.
hassan08 hassan08

2019/5/22

#
well the problem is with this line int answer = Integer.parseInt(Greenfoot.ask("How much is " + a + " + " + b + "?")); saying that It "cannot find the symbol.ask - method ask (java,lang.String)
hassan08 hassan08

2019/5/22

#
Super_Hippo wrote...
I am not gonna list all possible problems with this code. You should describe what your problem is.
well the problem is with this line int answer = Integer.parseInt(Greenfoot.ask("How much is " + a + " + " + b + "?")); saying that It "cannot find the symbol.ask - method ask (java,lang.String)
Super_Hippo Super_Hippo

2019/5/22

#
What version of Greenfoot are you using? Maybe you have to update Greenfoot to make use of the method.
Scorcher Scorcher

2019/5/22

#
Super_Hippo wrote...
What version of Greenfoot are you using? Maybe you have to update Greenfoot to make use of the method.
I second what Super_Hippo says. I just tested your code is a program and everything worked fine, except that I don't have your Message class, so I substituted "Message messagebox = new Message" with "System.out.println". It might be your version of Greenfoot like Hippo was saying, or it could be a problem with your Message class.
hassan08 hassan08

2019/5/24

#
Super_Hippo wrote...
What version of Greenfoot are you using? Maybe you have to update Greenfoot to make use of the method.
Scorcher wrote...
Super_Hippo wrote...
What version of Greenfoot are you using? Maybe you have to update Greenfoot to make use of the method.
I second what Super_Hippo says. I just tested your code is a program and everything worked fine, except that I don't have your Message class, so I substituted "Message messagebox = new Message" with "System.out.println". It might be your version of Greenfoot like Hippo was saying, or it could be a problem with your Message class.
I think it might be the version of greenfoot I am using I am using version 3.5.0
Super_Hippo Super_Hippo

2019/5/24

#
No, 3.5.0 already supports the ask method. So unless you have a your own Greenfoot class in your project or something, it should find the method. You could try to create a new scenario and only put in this code (comment out lines 25 and 30) and report back if you get this error. If yes, you could upload your scenario with available source, so we can check for ourselves.
You need to login to post a reply.