Example #1
0
 private void promptMarketPrice(Stock stock) {
   String marketPriceStr =
       getInput("Please enter the market price for " + stock.getStockSymbol() + ": ");
   double marketPrice = 0;
   try {
     marketPrice = Double.parseDouble(marketPriceStr);
     stock.setMarketPrice(marketPrice);
   } catch (Exception e) {
     System.out.println("Invalid Market Price!");
     promptMarketPrice(stock);
   }
 }
Example #2
0
  private void fetchStockPerformance(Stock stock) {
    double dividendYield = 0;
    if ("Common".equals(stock.getType())) {
      dividendYield = StockUtil.getDivYield(stock.getLastDividend(), stock.getMarketPrice());
    } else if ("Preferred".equals(stock.getType())) {
      dividendYield =
          StockUtil.getDivYield(
              stock.getFixedDividend(), stock.getParValue(), stock.getMarketPrice());
    }

    double peRatio = StockUtil.getPERatio(stock.getLastDividend(), stock.getMarketPrice());

    System.out.println("Dividend Yield : " + dividendYield);
    System.out.println("P/E Ratio : " + peRatio);
  }