Mighty Casey plays centerfield for the Toledo Mudhens and has the following lifetime hitting percentages: See image.
The above is called a probability distribution. A probability distribution is used in predicting the likelihood of an event occurring. See the following explanation of probability distributions using the example of flipping a coin at: http://stattrek.com/Lesson2/ProbabilityDistribution.aspx. Notice the distribution adds up to 100%.
Write a program to simulate a large number of times at bat (1000 or more) for Mighty Casey counting the number of outs, walks, singles, etc. to predict Mighty Casey’s batting average for next season and slugging percentage. This means you have to generate a random number (hint: between 1 and 100 and see PP notes for random number generation formulas) and based upon the value (i.e. probability) will determine if Mighty Casey gets a hit or an out. If it is a hit, then your program needs to determine what type of hit was based upon the probabilities given in the table above.
Use the formulas below to calculate the batting average and slugging percentage of Mighty Casey.
batting average = number of hits / (number of times at bat – number of walks)
slugging percentage = (number of singles + number of doubles * 2 + number of triples * 3 + number of homeruns * 4) /(number of times at bat – number of walks)