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

2012/9/10

Counter Class Error

ManiHallam ManiHallam

2012/9/10

#
this is my Counter class, but when I click on monies it does add them up. Could you please help me?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.util.List;

/**
 * Chocolate Dispenser Mchine
 * 
 * 
 * 
 * @version 1.0
 */
public class Counter extends Actor
{
    private int credit;
    private boolean moneyFound  = false;

    /**
     * Act - do whatever the Counter wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        coinFound();
        noteFound();
        getCredit();
        update();
    }

    /**
     * Counting all Coins in Money class, which are inserted into the Coin Insertion.
     */
    public void coinFound()
    {
        if (!moneyFound && !getWorld().getObjectsAt(517, 314, Money.class).isEmpty())
        {
            moneyFound = true; 
            List<Money> money2 = getWorld().getObjectsAt(517, 314, Money.class);
            Money money = money2.get(0);
            credit += money.getValue();
        }

        if (moneyFound && getWorld().getObjectsAt(517, 314, Money.class).isEmpty())
        {
            moneyFound = false;
        }
    }

    /**
     * Counting all Notes in Money class, which are inserted into the Note Insertion.
     */
    public void noteFound()
    {
        if (!moneyFound && !getWorld().getObjectsAt(664, 367, Money.class).isEmpty())
        {
            moneyFound = true;
            List<Money> money2 = getWorld().getObjectsAt(664, 367, Money.class);
            Money money = money2.get(0);
            credit += money.getValue();
        }

        if (moneyFound && getWorld().getObjectsAt(664, 367, Money.class).isEmpty())
        {
            moneyFound = false;
        }
    }

    /**
     * 
     */
    public int getCredit()
    {
        return credit;
    }

    /**
     * 
     */
    public void update()
    {
        ((Screen) getWorld().getObjects(Screen.class).get(0)).setText("Credit: " + credit);
    }
}
danpost danpost

2012/9/10

#
ManiHallam wrote...
this is my Counter class, but when I click on monies it does add them up.
Do you mean it does NOT add them up? Also, did you change any of your code since I last posted? To make your source available, you need to check the box to include source every time you upload the scenario.
ManiHallam ManiHallam

2012/9/11

#
Sorry. Yes, it does not add them up.
danpost danpost

2012/9/11

#
Did you see my last code post on the other discussion, 'Showing messages from Classes and updated messages from Counter'?
danpost danpost

2012/9/11

#
Also, see my code post that shows up first on page 3 of that same discussion. They go hand-in-hand with each other.
ManiHallam ManiHallam

2012/9/11

#
ok, I will. Thanks.
danpost danpost

2012/9/11

#
I should be back within 8 hours. Have a blessed day!
ManiHallam ManiHallam

2012/9/11

#
Thanks u2.
danpost danpost

2012/9/11

#
@ManiHallam, have you checked out those posts?
You need to login to post a reply.