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

2019/5/17

Need some help on Set Direction method?

lzg01 lzg01

2019/5/17

#
Im a little confused and lost on what im doing wrong. Could anyone help me? This is the entire code, i know im missing something but unsure how or where to add. The error says "Invalid Method declaration; return type required" by the PUBLIC WOMBAT import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class wombat here. * * @author (your name) * @version (a version number or a date) */ public class wombat extends Actor { private static final int NORTH = 0; private static final int EAST = 1; private static final int SOUTH = 2; private static final int WEST = 3; private int direction; public Wombat() { setDirection(East); } /** * Act - do whatever the wombat wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { } }
danpost danpost

2019/5/18

#
You named the class "wombat" (startting with a lowercase "w"). You cannot have a constructor by any other name -- not even "Wombat" (with an uppercase "W").
lzg01 lzg01

2019/6/3

#
danpost wrote...
You named the class "wombat" (startting with a lowercase "w"). You cannot have a constructor by any other name -- not even "Wombat" (with an uppercase "W").
ah i see alright,thankyou. now its telling me cannot find symbol -method setDirection(int) Maybe if i explain what I'm trying to do it would help better? Im trying to do exercise 1.5 where (Invoke the setDirection(int direction) method. Provide a parameter value and see what happens. Im just quite a bit lost public class wombat extends Actor { private static final int NORTH = 0; private static final int EAST = 1; private static final int SOUTH = 2; private static final int WEST = 3; private int direction; public wombat() { setDirection(EAST); } /** * Act - do whatever the wombat wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { } }
danpost danpost

2019/6/3

#
Maybe you should add a setDirection method:
private void setDirection(int dir)
{
    direction = dir;
}
You need to login to post a reply.