/**
 * Class name: SimulateGambling
 * A Java application to simulate a gamlber's ruin.
 *
 * @author Robert Sedgewick
 * @author Kevin Wayne
 * @version 1.2, 10/07/2026, modified by Takunari Miyazaki
 */

public class SimulateGambling {

  /**
   * Simulates a series of $1 bets, given an initial stake and a goal,
   * until the gambler goes broke or wins by achieving the goal, returning
   * the number of bets made for a win or 0 in case of a loss.
   *
   * @param stake - an initial stake
   * @param goal  - a goal
   * @return the number of bets to win or 0 in case of a loss.
   */
  public static int simulate(int stake, int goal) {
    // Remove the statement below and complete your implementation.
    return 0;
  }

  /**
   * main() method
   */
  public static void main(String[] args) {
    int stake  = Integer.parseInt(args[0]);  // gambler's stating bankroll
    int goal   = Integer.parseInt(args[1]);  // gambler's desired bankroll
    int trials = Integer.parseInt(args[2]);  // number of trials to perform

    int total_bets_to_win = 0;  // total number of bets made to win
    int wins = 0;               // total number of games won

    // repeat trials times
    for (int t = 0; t < trials; t++) {
      // perform one gambler's ruin simulation in the method simulate().
      int bets = simulate(stake, goal);
      if (bets > 0) {
	wins++;
	total_bets_to_win += bets;
      }
    }

    // print results
    System.out.printf("It resulted in %d wins out of %d trials.%n",
      wins, trials);
    System.out.printf("The percent of games won:          %10.2f%%%n",
      100.0*wins/trials);
    System.out.printf("The average number of bets to win: %10.2f%n",
      1.0*total_bets_to_win/wins);
  }
    
}
