Summary: Originally, object-oriented languages were designed to make simulation easier and perhaps more accurate. In this assignment, you will be developing a simple simulation of a racquetball game to consider some of the aspects of simulation and to get your "feet wet" with Java programming.
Note: While we have not yet learned all the issues in Java programming necessary to do this assignment, we will have covered them by the end of class on Monday. In any case, you can begin the design of the program now, and fill in the details as you learn them.
Citation: This assignment is based on a column by Henry M. Walker to be published in the ACM SIGCSE Bulletin.
Turning it in:
Leave your code in a publically readable directory, and email me the
location of that directory. Note that your directory should include
documentation generated by
Collaboration: You may work in group of up to size two, and may discuss your design with any size group. You may also work with each other on general debugging issues.
Racquetball is a two-player game played by two players on an indoor, enclosed court. One player serves the ball, the other returns (or attempts to return) the ball, and they continue to volley until one player misses. If the serving player wins the volley, that player receives a point. If the serving player misses the volley, the serve passes to the other player, and no points are scored. Play continues until the score is 11-0 (a shut out) or one player scores 21 points.
One way to model the game is to assign a probability to each player winning a volley when he or she "has the serve." Write a Java program that takes these two probabilities, and computes the results of one thousand (1000) games between the two players. The results should include the number and probability of wins and shut-outs.
Your program should have at least the three classes
Player, used to simulate each player,
Score, used to keep track of the score (and perhaps the serve, depending on your design),
RecordTable, used to keep track of wins/losses
If you'd like some more to do on this assignment, you might consider one or more of the following:
While we'll cover general issues to support this type of application (e.g., loops and array), we may not cover all of the specific issues. Here are a few tips to help you over some of the programming hurdles.
There is a good possibilitiy that we won't get to program input before
this assignment is due. Hence, you will take input from the command
line. You may recall that the
main method of a class
has one parameter, an array of strings. If you named that array
args, you can refer to its elements as
You can convert a string to an integer with
Java provides at least two ways to create random numbers, one from the
Math class, and one from a separate
If you call
Math.random() (that is, the class method
random of the
Math class), it will return
a pseudorandom number between 0.0 and 1.0.
If you create an instance,
r, of class
using something like
you can ask forRandom r = new Random()
On most (all?) computers, random numbers are generated using a random
number generator, an algorithm for computing a random-looking
(but not truly random) sequence. For some simulations, it is important
that you get the same sequence of random numbers each time. You can
seed the random number generator with
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Fri Sep 12 09:02:42 1997.
This page generated on Fri Dec 12 12:06:20 1997 by SiteWeaver.
Contact our webmaster at email@example.com