import java.util.ArrayList;

public class SimulateBetsApplication {

  public static void main(String[] args) {

    int stake  = Integer.parseInt(args[0]);  // gambler's starting 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 = 0; // total number of bets made
    int wins = 0;       // total number of games won

    // run simulation
    SimulateBets simulation = new SimulateBets(stake, goal, trials);
    simulation.simulate();
    ArrayList<BetResult> results = simulation.getResults();

    // count the total numbers of bets made and wins
    for (int i = 0; i < trials; i++) {
      total_bets += results.get(i).getBets();
      if (results.get(i).getWon()) wins++;
    }

    // find the most number of bets made with its trial # and result
    int max_bets = 0;
    int max_index = -1;
    boolean max_result = false;
    for (int i = 0; i < trials; i++)
      if (results.get(i).getBets() > max_bets) {
        max_bets = results.get(i).getBets();
        max_index = i;
        max_result = results.get(i).getWon();
      }

    // find the 2nd most number of bets made with its trial # and result

    // find the 3rd most number of bets made with its trial # and result

    // find the longest winning streak
    
    // 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:         %9.2f%%%n",
      100.0*wins/trials);
    System.out.printf("The average number of bets made:  %9.2f%n",
      1.0*total_bets/trials);
    if (max_result)
      System.out.printf("The most number of bets made:     %6d for trial #%d for a win.%n", max_bets, max_index);
    else
      System.out.printf("The most number of bets made:     %6d for trial #%d for a loss.%n", max_bets, max_index);
    
  }
    
}
