/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package coingame;

import java.util.*;

public class Change {

  ArrayList<Coin> coins = new ArrayList<Coin>();

  public Change(){}

  public Change(int count){
    for(int i = 0; i < count; i++){
      coins.add(new Coin());
    }
  }

  public Change(ArrayList<Currency> values) {
    for (Currency value : values) {
      coins.add(new Coin(value));
    }
  }

  public void flipAllCoins() {
    for (Coin c : coins) {
      c.flip();
    }
  }

  public void flipSomeCoins(ArrayList<Integer> indexes) {
    for (int i : indexes) {
      coins.get(i).flip();
    }
  }

  public int computeSum() {
    int sum = 0;
    for (Coin c : coins) {
      if (!c.isHeads()) {
        sum = sum + c.getValue();
      }
    }
    return sum;
  }

  public String toString() {
    String result = "";
    for (Coin c : coins) {
      result = result+c+" ";
    }
    result = result + " Total: "+computeSum();
    return result;
  }
}