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

2017/3/26

Accessing Method in TestCase

rockon411 rockon411

2017/3/26

#
I am trying to test a method from one of my subclasses and I keep getting the error "cannot find symbol - method addMoney()." I've never had issues seeing methods while testing before. This is my test.
public void setUp()
    {
        island = new Island();
        bob = new Minnow();
    }
    public void testAddMoney()
    {
        island.add(bob, 2, 2);
        run(island, 51);
        bob.addMoney();
        assertEquals(11, island.getMoney());
    }
and here is the method that I am trying to test in my subclass
public void addMoney()
    {
       Island island = (Island) getWorld();
       island.addFunds(1);
    }
and the code in my world subclass
public int addFunds(int funds)
    {
        total = total + funds;
        if(food <= 0)
        {
            return 0;
        }
        else
        {
            return funds;
        }
    }
danpost danpost

2017/3/26

#
Is the 'addMoney' method in the Minnow class (or a class from which it is an extension of)?
rockon411 rockon411

2017/3/26

#
it's in the minnow claa
Nosson1459 Nosson1459

2017/3/26

#
When you create the bob variable what type do you set it to (e.g. int, double, String, Actor, Minnow, etc.)? To access the methods in Minnow it has to be type Minnow or something that extends from it, no parents of it.
danpost danpost

2017/3/27

#
Try changing line 10 to:
((Minnow)bob).addMoney();
rockon411 rockon411

2017/3/27

#
Thanks guys!
You need to login to post a reply.