Java Reference
In-Depth Information
15.
using the traffic lights data in section 6.8, write a program to simulate the situation at the
lights for a 30-minute period. print the number of cars in each queue each time the light
changes.
16.
Write a program to estimate the square root of 59.
17.
Write a program to read a positive integer n and estimate the square root of n .
18.
Write a program to read a positive integer n and estimate the cube root of n .
19.
Write a program to simulate the collection of bottle caps to spell APPLE . in every 100 caps,
a and e occur 40 times each, p occurs 10 times and l occurs 10 times. do 50 simulations
and print the average number of caps per simulation.
20.
the lottery requires people to pick seven numbers from the numbers 1 to 40. Write a
program to randomly generate and print five sets of seven numbers each (one set per line).
no number is to be repeated in any of the sets; that is, exactly 35 of the 40 numbers must be
used. if a number ( p , say) is generated that has been used already, the first unused number
after p is used. (assume that 1 follows 40.) For example, if 15 is generated but has been used
already, 16 is tried, but if this has been used, 17 is tried, and so on, until an unused number
is found.
21.
a function f(x) is defined for 0 £ x £ 1, such that 0 £ f(x) < 1 for all 0 £ x < 1. Write a
program to estimate the integral of f(x) from 0 to 1. hint: estimate the area under the curve
by generating points ( x , y ), 0 £ x < 1, 0 £ y < 1.
22.
a gambler pays $5 to play the following game. he throws two six-sided dice. if the sum of
the two numbers thrown is even, he loses his bet. if the sum is odd, he draws a card from
a standard pack of 52 playing cards. if he draws an ace, 3, 5, 7 or 9, he is paid the value of
the card plus $5 (ace counts as 1). if he draws any other card, he loses. Write a program to
simulate the playing of 20 games and print the average amount won by the gambler
per game.
Search WWH ::




Custom Search