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

2012/12/6

calculating totals of cards flipped

drpotts2000 drpotts2000

2012/12/6

#
Im currently trying to add a total of cards shown to my binary project. What is confusing is that I am supposed to: call ‘setCount’ on ‘counter’ and pass in the ‘total’ I am very new to Java and really don't understand what is being asked here. this is the 2 methods that I am dealing with. I need to implement this in the updateCounter method. Any help would be greatly appreciated. public void updateCounter() { int total = calculateTotal(); Counter counter = getCounter(); } private int calculateTotal() { int total = 0; for ( Card card: getCards ()) { if (card.isShown()) { card.getValue(); total++; } }
drpotts2000 drpotts2000

2012/12/6

#
Nevermind. I got it.
vonmeth vonmeth

2012/12/6

#
It might need to look something like this.
public void updateCounter()
    {
        int total = calculateTotal();
        Counter counter = getCounter();
        counter.setCount(total);
    }
private int calculateTotal()
    {
      int total = 0;
      
      for ( Card card : getCards ())
            {
                if (card.isShown())
                    {
                        total += card.getValue();
                    } 
            }
      return total;
    }
"total++" will simply increment the value of "total" by 1. It would count the number of cards that are currently being shown instead of the value of the card.
You need to login to post a reply.