Package net.gouline.riskybusiness

Source Code of net.gouline.riskybusiness.App

package net.gouline.riskybusiness;

import net.gouline.riskybusiness.model.UnsettledBet;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

/**
* Main entry application.
*
* @author Mike Gouline
*/
public class App {
  /**
   * Main entry point.
   *
   * @param args Command line arguments.
   */
  public static void main(String[] args) {
    if (args.length < 2) {
      System.err.println("Usage: RiskyBusiness SETTLED_FILENAME UNSETTLED_FILENAME");
      System.exit(1);
      return;
    }

    // Create app and supply input
    new App().evaluate(args[0], args[1]);
  }

  private RiskEvaluator riskEvaluator;

  public App() {
    riskEvaluator = new RiskEvaluator();
  }

  public void evaluate(String settledFilename, String unsettledFilename) {
    System.out.println();
    System.out.println("RiskyBusiness");
    System.out.println();

    List<UnsettledBet> unsettledBets;
    try {
      unsettledBets = riskEvaluator.evaluate(settledFilename, unsettledFilename);
    } catch (IOException e) {
      System.err.print("Error reading file: " + e.getMessage());
      System.exit(1);
      return;
    }

    DecimalFormat decimalFormat = new DecimalFormat("#.##");
    for (int i = 0, iN = unsettledBets.size(); i < iN; ++i) {
      UnsettledBet unsettledBet = unsettledBets.get(i);

      System.out.println("# " + i);
      System.out.println("Customer: " + unsettledBet.getCustomerId());
      System.out.println("Event: " + unsettledBet.getEventId());
      System.out.println("Participant: " + unsettledBet.getEventId());
      System.out.println("Stake: $" + decimalFormat.format(unsettledBet.getStake()));
      System.out.println("To Win: $" + decimalFormat.format(unsettledBet.getToWin()));

      Map<RiskEvaluator.RiskType, String> risks = unsettledBet.getRisks();
      if (risks.values().size() > 0) {
        System.out.println("Risks:");
        for (String message : risks.values()) {
          System.out.println("\t- " + message);
        }
      }
    }
  }
}
TOP

Related Classes of net.gouline.riskybusiness.App

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.