The Practice and Philosophy of Object-Oriented Programming in Java

New Practice Problems for Chapter 6

Roulette. A roulette wheel has 38 equally sized slots. The wheel is spun and a little ball spins with it, eventually landing in one of the slots. Two of the slots are green, and of the remaining 36 half are red and half are black. A common bet is to place $1 on red. This means that the player wins a dollar if the ball lands in a red slot, and loses a dollar if lands on green or black.

Write a Monte Carlo simulation that calculates the expected loss from this wager.

Pace Band.  Suppose you are running a 5-mile road race and you want to keep a steady pace of 6:25 per mile. If you start your watch when the gun sounds, the time on your watch at the first mile marker would be 6:25; at the second mile marker, your watch would read 12:50; at the third, 19:15, and so on. Prior to the advent of sophisticated GPS watches, some runners would wear these times printed on a so-called pace band around their wrist. This enabled them to determine their progress at each mile marker without having to do any mental math.

Write a program that prompts the user for a distance to be run in miles and a target pace, and outputs the times that that would appear on a pace band for that goal. The distance of a race may not be a whole number of miles (a marathon, for example, is 26.2 miles long) but we are only interested in our progress at whole mile intervals so you may assume that the distance is entered as an integer. The pace will be entered in M:SS format. The output will be in MM:SS or HH:MM:SS format.

            Enter distance in miles: 5
            Enter target pace: 6:25
            Enter distance in miles: 10
            Enter target pace: 6:59

Return to Companion Site home page