CS 140 - Homework 4 Due Monday September

Create a new folder in your student folder on the T: drive named HW4 and copy a blank Program.java to the HW4 folder.

To see how your homework should finally look run my version by double clicking on My Computer and going to the folder T:/Harcourt/Fall09/CS140/HW4 and then double click on the file run.bat.

The problem

Modify the Gamblers Ruin simulation we developed in class so that it prints a message every time the user tosses ten heads in a row or tosses ten tails in a row as well as the total number of heads, tails, and current account balance.

  1. Recall that to test if two numbers are equal you need to use the == operator. For example
      if (x == 10) {
         StdOut.println("X is ten!");  
      }
    
  2. Your program should prompt the user for the initial investment.
  3. Your program should prompt the user for the number of times they want to toss the coin.
  4. Here's the output of a sample run of my program. Remember, its different every time.
      Enter initial investment: 10
      Enter the number of times you want to toss the coin: 3000
      We rolled 10 tails at roll 822
      We rolled 10 tails at roll 2535
      We rolled 10 heads at roll 2763
      We rolled 10 tails at roll 2885
      heads = 1478
      tails = 1522
      balance = -34