Java Reference
In-Depth Information
eXerCISeS 6
1.
Write a program to request two numbers,
m
and
n
, and print 25 random numbers from
m
to
n
.
2.
explain the difference between random and pseudorandom numbers.
3.
modify program p6.3 to give a user problems in subtraction.
4.
modify program p6.3 to give a user problems in multiplication.
5.
modify program p6.3 to incorporate a scoring system. For example, for two attempts at a
problem, you can give 2 points for a correct answer on the first attempt and 1 point for a
correct answer on the second attempt.
6.
rewrite program p6.3 so that it presents the user with a menu that allows him to choose
what kinds of problems he gets (addition, subtraction, or multiplication).
7.
Write a program to simulate 1,000 throws of a die and determine the number of 1s, 2s, 3s,
4s, 5s, and 6s that show. Write the program (a) without using an array and (b) using an array.
8.
Write a program to simulate the weather for 60 days using the probabilities in section 6.7.
9.
in the manufacture of electric bulbs, the probability that a bulb is defective is 0.01. simulate
the manufacture of 5,000 bulbs, indicating how many are defective.
10.
a die is weighted such that 1s and 5s come up twice as often as any other number. simulate
1,000 throws of this die, indicating the frequency with which each number occurs.
11.
modify program p6.6 to calculate the average waiting time for customers and the total idle
time for each counter.
12.
one-Zero is a game that can be played among several players using a six-sided die. on his turn,
a player can throw the die as many times as he wants. his score for that turn is the sum of the
numbers he throws
provided he does not throw
a 1. if he throws a 1, his score is 0. suppose
a player decides to adopt the strategy of ending his turn after seven throws. (of course, if he
throws a 1 before the 7
th
throw, he must end his turn.) Write a program to play 10 turns using this
strategy. For each turn, print the score obtained. also, print the average score for the 10 turns.
Generalize the program to request values for
numTurns
and
maxThrowsPerTurn
and print the
results as described.
13.
Write a program to simulate the game of
Snakes and Ladders
. the board consists of 100
squares. snakes and ladders are input as ordered pairs of numbers,
m
and
n
. For example,
the pair
17 64
means that there is a ladder from 17 to 64, and the pair
99 28
means that
there is a snake from 99 to 28.
simulate the playing of 20 games, each game lasting a maximum of 100 moves. print the
number of games that were completed in the 100 moves and the average number of moves
per game for completed games.
14.
Write a program to play a modified game of nim (section 6.6) in which there are two heaps
of matches and a player, on his turn, may choose from either one. however, in this case, a
player
wins
if he picks up the last match.
Search WWH ::
Custom Search