|Software Development, Design Choices, Class Design,
Recursion and Iteration, Testing, and Command-line Arguments
|A Racquetball or Volleyball Simulation|
The results from the sample output illustrate that this simulation is very sensitive to the initial probabilities. For example, if A has a 40% chance of winning a volley, then A will win almost no games. Since these results may not be intuitive, it is natural to wonder how this simulation might be tested.
Although eventually a user will want to view only the results of the simulation, a developer may want to know how processing proceeds at a reasonable level of detail. To obtain such information, it is natural to add various print statements to show intermediate values. One way to proceed would be to insert these print statements for testing and then remove them when the program is believed to be correct and complete. However, this approach has at least two drawbacks:
Instead, in order to trace code when desired, a static variable printGame can be added to the class. When this variable is true, the score of each game is printed, and when this variable is false, the scores for the individual games are not printed. This approach is illustrated in program Game3Recur.java.
Run Game3Recur.java with printGame being true and again with the variable false. Explain why this change results in any differences in what is printed.
Describe the extent to which having printGame helps you check the program for correctness.
To refine tracing capabilities, two different levels of tracing might be defined:
Revise Game3Recur.java to implement these two tracing levels. You will need to add at least one additional tracing variable, and you will need to organize print statements according to the type of tracing they support. Additional print statements also may be needed.
What other tracing might be helpful to establish the simulation is correct?
Consider the following commentary:
Technical Aside: The sample output shown in the first lab may be explained mathematically by noting that, to score a point, a team must win two volleys in a row. Thus, if A's chance of winning a volley is 0.4, A's chance of winning a point is 0.4x0.4 = 0.16. B's chance of winning a point in this case is 0.6x0.6 = 0.36, which is more than double A's chance of scoring a single point.
To what extent does this observation justify the output of this simulation?