public class SharePie {
  private Map shares = new HashMap();

// Pominęliśmy metody dostępowe oraz inne proste metody

  public double getAmount() {
    double total = 0.0;
    Iterator it = shares.keySet().iterator();
    while(it.hasNext()) {
      Share loanShare = getShare(it.next());
      total = total + loanShare.getAmount();
    }
    return total;
  }

  public SharePie minus(SharePie otherShares) {
    SharePie result = new SharePie();
    Set owners = new HashSet();
    owners.addAll(getOwners());
    owners.addAll(otherShares.getOwners());
    Iterator it = owners.iterator();
    while(it.hasNext()) {
      Object owner = it.next();
      double resultShareAmount = getShareAmount(owner) –
        otherShares.getShareAmount(owner);
      result.add(owner, resultShareAmount);
    }
    return result;
  }

  public SharePie plus(SharePie otherShares) {
    // Podobnie do implementacji operacji minus()
  }

  public SharePie prorated(double amountToProrate) {
    SharePie proration = new SharePie();
    double basis = getAmount();
    Iterator it = shares.keySet().iterator();
    while(it.hasNext()) {
      Object owner = it.next();
      Share share = getShare(owner);
      double proratedShareAmount =
        share.getAmount() / basis * amountToProrate;
      proration.add(owner, proratedShareAmount);
    }
    return proration;
  }

}
