Write a java program that takes in integers values stake and goal and it does on
ID: 3592696 • Letter: W
Question
Write a java 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
}
EDITED QUESTION!!!!
The output doesn't matter that much but I need to use plotBars to plot each value that is in the array. Last time I posted question someone asked for more info to use plotbars and I posted link and I was threaten to be banned here. So I wont do that again.
The program needs to take each value the while loop creates and store it in array. We can't know how how many values there will be until it reach the goal so the array needs to be very big, it should be able to take 1000000 values. If it needs to take more values it will crash. Then I need to create new array that take old array and make all the values on the interval 0-1 so I can later use them for plotbars.
If you really need it to print something out. Just print out the array that you create for the problem. Lets say you do java Gambler 50 60. Then it should print out array with values going something like this randomily: 51 52 53 52 51 52 53 54 55 54 55 56 57 56 55 54 55 56 55 57 58 59 60.
Explanation / Answer
import java.util.*; public class Exercise63 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Input the first number : "); int a = in.nextInt(); System.out.print("Input the second number: "); int b = in.nextInt(); System.out.println("Result: "+result(a, b)); } public static int result(int x, int y) { if(x == y) return 0; if(x % 6 == y % 6) return (x y) ? x : y; } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.