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

2013/9/15

System.out.println statement wont display help!

joel joel

2013/9/15

#
public class Main extends World { /** * Constructor for objects of class Main. * */ public Main() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super (600, 400, 1); } //This method is called to check if a new highscore was reached. public void checkNewHighscore() { int highScore =10000; int myScore =100001; if ( myScore > highScore) { System.out.println("Congratulations, you reached a new highscore!"); System.out.printf("The old highscore was %d. \n", highScore); highScore = myScore; System.out.println("The new highscore is "+Integer.toString(highScore)); } else { System.out.println("Sorry, no new highscore!"); } } }
Gevater_Tod4711 Gevater_Tod4711

2013/9/15

#
Are you shure that this method is called from a class in your scenario? When the method is not called there also is nothing printed on the screen. To try it you can pause your scenario, rightclick on the world panel and call the method manually. If then also nothing is printed on your console that might be a bug (although I can hardly imagine that).
sametguzelgun sametguzelgun

2013/9/15

#
public class Main extends World
{

    /**
     * Constructor for objects of class Main.
     * 
     */
    public Main()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super (600, 400, 1); 
    }
    
    //This method is called to check if a new highscore was reached.
     public void checkNewHighscore()
      {
         int highScore =10000;
         int myScore =100001;
         
         
         if ( myScore > highScore)
           {
             System.out.println("Congratulations, you reached a new highscore!");
             System.out.printf("The old highscore was %d. \n", highScore);
             highScore = myScore;
             System.out.println("The new highscore is "+Integer.toString(highScore));
            }
            else
            {
                System.out.println("Sorry, no new highscore!");
            }
        }
        public void act()
        {
            checkNewHighscore();
        }
}
sametguzelgun sametguzelgun

2013/9/15

#
Act done in the method should call the method you want to run.
joel joel

2013/9/15

#
yeah yeah it works when i called it from the , rightclick pop up menu tnx tnx!!!
joel joel

2013/9/15

#
@sametguzelgun tnx for new method
danpost danpost

2013/9/15

#
Actually, if you call the method from the 'act' method as sametguzelgun suggests, the method will execute every time the score increases above the last high score until the game is ended. Best would be to call the method from a method that is executed when the game is over (have a 'checkGameOver' method called from the 'act' method and if the game is determined over in that method, call the 'checkNewHighscore' method from there).
joel joel

2013/9/15

#
@danpost ok i will do that, tnx!
8bitcarrotjuice 8bitcarrotjuice

2013/9/17

#
Sorry I have to write here, but for some reason I can't create a new thread and I though this is related to my issue: When I try and use the Scanner (java.util) class in the Greenfoot terminal, it does not work and I can't type in anything... This code(in a world constructor) won't work: System.out.print("Hello!"); Scanner scan= new Scanner(System.in); System.out.print("\nEnter number 1: "); int i=scan.nextInt(); System.out.print(i);
sametguzelgun sametguzelgun

2013/9/17

#
8bitcarrotjuice wrote...
Sorry I have to write here, but for some reason I can't create a new thread and I though this is related to my issue: When I try and use the Scanner (java.util) class in the Greenfoot terminal, it does not work and I can't type in anything... This code(in a world constructor) won't work: System.out.print("Hello!"); Scanner scan= new Scanner(System.in); System.out.print("\nEnter number 1: "); int i=scan.nextInt(); System.out.print(i);
Because closing Grenfoot. Instead, we should choose the method of JOptionPane class showInputDialog not you?
You need to login to post a reply.