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); } }