Example #1
0
  public float getPERatio(StockContainer stockContainer, float price) {

    float retValue = Constants.ZERO_VALUE;

    // check for the minimum negative cases
    if ((stockContainer == null || stockContainer.getLastDividend() < Constants.ZERO_VALUE)
        && price < Constants.ZERO_VALUE) {
      throw new InvalidStockEception(Constants.INVALID_STOCK_VALUES);
    } else {
      retValue = price / stockContainer.getLastDividend();
    }

    return retValue;
  }
Example #2
0
  public float getDividendYield(StockContainer stockContainer, float price) {

    boolean canThrowError = Boolean.FALSE;
    float retValue = Constants.ZERO_VALUE;

    // check for the minimum negative cases
    if (stockContainer == null && price < Constants.ZERO_VALUE) {
      canThrowError = Boolean.TRUE;
    } else {
      // Calculate the Value
      switch (stockContainer.getType()) {
        case COMMON:
          retValue = stockContainer.getLastDividend() / price;
          break;
        case PREFERRED:
          retValue = stockContainer.getFixedDividend() * stockContainer.getParValue() / price;
          break;
        default:
          canThrowError = Boolean.TRUE;
          break;
      }
    }

    // Raise exception
    if (canThrowError) {
      throw new InvalidStockEception(Constants.INVALID_STOCK_VALUES);
    }
    return retValue;
  }