| CPSC/DTSC 115L: Introduction to Computer Science | Fall 2026 |
BetResult.javaYou will first work on the file BetResult.java for the warm-up exercise and then the file SimulateBetsApplication.java to simulate Gambler's ruin. While it is required to run the Java application SimulateBetsApplication, the file SimulateBets.java has been completed (and should not be edited).
SimulateBets.java
SimulateBetsApplication.java
All results are now stored in the list named results, an ArrayList object. The first for loop then counts the total number of bets made and the total number of wins from the list. The second for loop finds the most number of bets made with its trial number (i.e., index in the list) and result, whether it resulted in a win. You are now to add code segments to determine and print, from the list results,SimulateBets simulation = new SimulateBets(stake, goal, trials); simulation.simulate(); ArrayList<BetResult> results = simulation.getResults();
After implementing and compiling it successfully, run your program with five test cases, including the above example. When completed, show your work to the instructor or a TA.miyazaki@lab:~/cpsc115/lab7$ java SimulateBetsApplication 100 200 1000 It resulted in 501 wins out of 1000 trials. The percent of games won: 50.10% The average number of bets made: 10089.42 The most number of bets made: 49474 for trial #552 for a win. The 2nd most number of bets made: 49310 for trial #168 for a loss. The 3rd most number of bets made: 47088 for trial #285 for a win. The longest winning streak: 11 wins
https://moodle.trincoll.edu/mod/assign/view.php?id=664499If you have completed this laboratory early, stay and work on Homework 6 for the rest of the time.
|
|
CPSC/DTSC 115L home page |
|
|