Computer Science Fundamentals (CS153 2003S)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]

[EC]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Lab Writeups]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Experiments in Java]
[Scheme Reference]
[Scheme Report]
[CS153 2002S (Walker)]
[CS151 2003S (Rebelsky)]
[CS152 2000F (Rebelsky)]
[SamR]
Assigned: Tuesday, 1 April 2003
Due: Tuesday, 8 April 2003
Summary:
Originally, objectoriented 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.
Citation: This assignment is based on a column by Henry M. Walker be published in some issue of the ACM SIGCSE Bulletin, although it was designed before that issue was published.
Turning it in: Use the ECA.
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.
Contents:
Racquetball is a twoplayer 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 110 (a shut out) or one player scores 21 points.
Your goal is twofold: First, write a program that narrates one match between two players. Next, write a program compute the liklihood of a player winning a game of Raquetball by simulating a large number of matches. Your second program should report at least four results, given two players, A and B: (1) the number of wins for A in the number of matches specified, (2) the probability of A winning, (3) the number of shutouts (by either player) in the number of matches specified, and (4) the probability of a shutout occuring.
In order to write both programs, you'll need to find a way to model various
aspects of raquetball. The simplest technique is to assign to each player
a probability of winning a volley when the player has the serve
.
To simulate a match, you start the serve with a player, determine whether
or not that player wins. If so, you assign a point to that player for the
match. If not, you switch the serve to the other player.
A more complex and more realistic mechanism is to assign to each player a probability of returning the ball. I assume you can figure out how to use this probabilty.
You must create at least the following five classes for the two parts of the assignment.
Player
, used to simulate each player,
Score
, used to keep track of the score of one match (and
perhaps the serve, depending on your design),
RecordTable
, used to keep track of wins/losses/shutouts.
MatchReporter
, used to report on one match. This class
should contain a main
method.
StatisticsCalculator
, used to compute the various
statistics mentioned above. This class should also contain a
main
method.
If you'd like some more to do on this assignment, you might consider one or more of the following:
In order to simulate the match, you'll need a random
sequence
of numbers. Java provides at least two ways to create random sequences
of numbers, one from the Math
class, and one from a separate
Random
class.
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 Random
,
using something like
Random r = new Random()
you can ask for r.nextDouble()
, r.nextFloat()
,
r.nextInt()
,, or r.nextLong()
.
By pseudorandom
I mean that it is generated algorithmically, but
it is still hard to predict. On most (all?) computers, random numbers
are generated using a random number generator, an algorithm for
computing a randomlooking (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 r.setSeed()
.
Tuesday, 1 April 2003 [Samuel A. Rebelsky]
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]

[EC]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Lab Writeups]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Experiments in Java]
[Scheme Reference]
[Scheme Report]
[CS153 2002S (Walker)]
[CS151 2003S (Rebelsky)]
[CS152 2000F (Rebelsky)]
[SamR]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Tue May 6 09:19:39 2003.
The source to the document was last modified on Tue Apr 1 22:29:00 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2003S/Homework/hw.03.html
.
You may wish to validate this document's HTML ; ; Check with Bobby
Samuel A. Rebelsky, rebelsky@grinnell.edu