Package ipm.gerdc.baccarat.util

Source Code of ipm.gerdc.baccarat.util.GenReport

/**
* @Author: Edmond Hoi
* @Description: IPM-ESAP-GERDC
* @Date: 2010.09.01
*/
package ipm.gerdc.baccarat.util;

import ipm.gerdc.baccarat.model.GameInfoBean;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Iterator;
import java.util.List;

public class GenReport {
  private static long numOfGames = 0;

  private static double totalWager = 0, totalPayback = 0;

  /**
   * Report header
   */
  private static void genHeader(BufferedWriter bw) throws Exception {
    StringBuffer sb = new StringBuffer();
    sb.append(" Game ID");
    sb.append(String.format("%11s", "PCard 1"));
    sb.append(String.format("%11s", "PCard 2"));
    sb.append(String.format("%11s", "PCard 3"));
    sb.append(String.format("%11s", "BCard 1"));
    sb.append(String.format("%11s", "BCard 2"));
    sb.append(String.format("%11s", "BCard 3"));
    sb.append(GameTools.TAB);
    sb.append("  vs. ");
    sb.append("Game Result");
    sb.append(String.format("%11s", "BOPlayer"));
    sb.append(String.format("%11s", "BOBanker"));
    sb.append(String.format("%11s", "BOTie"));
    sb.append(String.format("%11s", "Wager"));
    sb.append(String.format("%11s", "Payback"));
    sb.append(String.format("%13s", "Balance"));
    bw.write(sb.toString());
    bw.newLine();
  }

  /**
   * Report Horizontal line
   */
  private static void genHLine(BufferedWriter bw) throws Exception {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i <= 165; i++) {
      sb.append("=");
    }
    bw.write(sb.toString());
    bw.newLine();
  }

  /**
   * Build report body
   */
  private static void genBody(List<GameInfoBean> gameList, BufferedWriter bw) throws Exception {
    numOfGames = gameList.size();
    Iterator<GameInfoBean> itor = gameList.iterator();
    while (itor.hasNext()) {
      GameInfoBean bean = itor.next();
      StringBuffer sb = new StringBuffer();
      sb.append(GameTools.SPACE);
      sb.append(bean.getGameID());
      sb.append(GameTools.SPACE);
      sb.append(String.format("%11s", bean.getPlayerCard1()));
      sb.append(String.format("%11s", bean.getPlayerCard2()));
      sb.append(String.format("%11s", bean.getPlayerCard3()));
      sb.append(String.format("%11s", bean.getBankerCard1()));
      sb.append(String.format("%11s", bean.getBankerCard2()));
      sb.append(String.format("%11s", bean.getBankerCard3()));
      sb.append(GameTools.TAB);
      sb.append("(" + bean.getBankerPoint() + "-" + bean.getPlayerPoint() + ") ");
      sb.append(String.format("%11s", bean.getResultNum()));
      sb.append(String.format("%11s", GameTools.formatAmount(bean.getBetOnPlayer())));
      sb.append(String.format("%11s", GameTools.formatAmount(bean.getBetOnBanker())));
      sb.append(String.format("%11s", GameTools.formatAmount(bean.getBetOnTie())));
      sb.append(String.format("%11s", GameTools.formatAmount(bean.getBettingAmount())));
      sb.append(String.format("%11s", GameTools.formatAmount(bean.getReturnAmount())));
      sb.append(String.format("%13s", GameTools.formatAmount(bean.getBalance())));
      totalWager += bean.getBettingAmount();
      totalPayback += bean.getReturnAmount();
      bw.write(sb.toString());
      bw.newLine();
    }
  }

  /**
   * Build report footer
   */
  private static void genFooter(BufferedWriter bw) throws Exception {
    StringBuffer sb = new StringBuffer();
    sb.append("Number of games: ");
    sb.append(numOfGames);
    sb.append(GameTools.TAB);
    sb.append(GameTools.TAB);
    sb.append("Player total wager: $");
    sb.append(GameTools.formatAmount(totalWager));
    sb.append(GameTools.TAB);
    sb.append(GameTools.TAB);
    sb.append("Player total payback: $");
    sb.append(GameTools.formatAmount(totalPayback));
    sb.append(GameTools.TAB);
    sb.append(GameTools.TAB);
    sb.append("Player balance: $");
    sb.append(GameTools.formatAmount(totalPayback - totalWager));
    bw.write(sb.toString());
    bw.newLine();
  }

  public static void genReport(List<GameInfoBean> gameList) {
    try {
      BufferedWriter bw = new BufferedWriter(new FileWriter(SysConfig.getReportFile() + GameTools.getCurrentTime() + ".TXT"));
      genHeader(bw);
      genHLine(bw);
      genBody(gameList, bw);
      genHLine(bw);
      genFooter(bw);
      bw.close();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}
TOP

Related Classes of ipm.gerdc.baccarat.util.GenReport

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.