How to add a return statement for a method - beginner
<p>When i enter a value (<code>202 cents</code>) it should give me this amount either in <code>5 cents or 2 cents</code> coins. Everything works fine in my code, but the output is given as System.out statement in the <code>TwoCent</code> and <code>FiveCent</code> class it self. WHat i want to do is to <code>return</code> the number of <code>5 cents</code> and <code>2 cents</code> coins so that i could capture and display it in my <code>Test</code> class.</p>

<p>Note: In the code below, the number of 2 and 5 cents coins are returned(displayed/printed to the console) from that class it self. but i want to modify the code so those methods (in the <code>TwoCents</code> and <code>FiveCents</code> classes) will <code>return</code> and <code>int</code> may be with the amount of coins. I should be able to get these values and display from the <code>Test</code> class only.</p>

<pre><code>   public abstract class Coin {
    protected Coin co;
    public abstract void finCoin(Money m);
    public void setnext(Coin c) {
        co = c;
    }
}

public class TwoCent extends Coin{

    @Override
    public void finCoin(Money m) {
        if(m.getChange()%2==0){
          System.out.PrintLn("Return "+ m.getChange/2);
    else {
        int remainngCoins=m.getChange()*((m.getChange/2)*2));
        m.setChange(remainngCoins);
        co.setnext(m);
    }
}


public class FiveCent extends Coin{

    @Override
    public void finCoin(Money m) {
        if(m.getChange()%5==0){
          System.out.PrintLn("Return "+ m.getChange/5);
    else {
        int remainngCoins=m.getChange()*((m.getChange/5)*5));
        m.setChange(remainngCoins);
        co.setnext(m);
    }
}

public class Test {
public void showcoin(){
Coin f = new FiveCent();
        Cash t = new TwoCent();

        f.setSuccessor(t);

        Money cr = new Money(200);
        f.finCoin(cr);
}
}
</code></pre>
