Question
Write a program that takes in integers values stake and goal and it does only one simulation and store the value cash for each itaration
Write a program that takes in integers values stake and goal and it does only one simulation and store the value cash for each itaration in array.
To solve this problem you need to know this: You don't know how many itarations will be, so create a large enough array in the beginning, like with N = 100000 and let the program crash if the simulation will get bigger than that. Also create a new array for the first array that scale the values so they are on the interval 0.0 to 1.0.
Use the following code as a skeleton for the program!
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 cash = stake; while (cash > 0 && cash < goal) { bets++; if (Math.random() < 0.5) cash++; // win $1 else cash--; // lose $1 }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started