Write a program that plays the Rock-Paper-Scissor game. Have... randomly select Rock, Paper, or Scissor and then prompt the...

advertisement
AP Computer Science – Chapter 1, assignment 2
Name: _________________
1. Write a program that plays the Rock-Paper-Scissor game. Have the computer
randomly select Rock, Paper, or Scissor and then prompt the user for their choice.
First one to win 3 times wins. Display the results after every turn. A sample
display is shown below:
Enter sissor
1
The computer
Enter sissor
2
The computer
Enter sissor
0
The computer
Enter sissor
2
The computer
Enter sissor
1
The computer
(0), rock (1), paper (2)
is rock, the user is rock, Draw.
(0), rock (1), paper (2)
Score: user=0, computer=0
is rock, the user is paper,You win.
(0), rock (1), paper (2)
is paper,the user is sissor, You win.
(0), rock (1), paper (2)
Score: user=1, computer=0
is sissor, the user is paper,You lose.
(0), rock (1), paper (2)
is sissor, the user is rock, You win.
Score: user=2, computer=0
Score: user=2, computer=1
Score: user=3, computer=1
User wins!
2. Use a Monte-Carlo simulation to verify the value of PI. Using a circle with a
radius of 1 and a bounding square with a length of 2. Pick random points within the
square and use the distance formula to determine if the point also lies within the
circle boundry. Using a ratio of hit counts to total attempts, estimate PI and
compare with Math.PI. Try an attempt count of 1,000,000. Try multiple
simulations and display the results.
Download