subject

Calculate a player's batting statistics. Console

Welcome to the Batting Average Calculator.

Enter number of times at bat: 5

0 = out, 1 = single, 2 = double, 3 = triple, 4 = home run

Result for at-bat 0: 0

Result for at-bat 1: 1

Result for at-bat 2: 0

Result for at-bat 3: 2

Result for at-bat 4: 3

Batting average: 0.600

Slugging percent: 1.200

Another batter? (y/n): y

Enter number of times at bat: 3 0 = out, 1 = single, 2 = double, 3 = triple, 4 = home run

Result for at-bat 0: 0

Result for at-bat 1: 4

Result for at-bat 2: 0

Batting average: 0.333

Slugging percent: 1.333

Another batter? (y/n): n

Operation

This application calculates the batting average and slugging percentage for one or more baseball or softball players. For each player, the application first asks for the number of at bats. Then, for each at bat, the application asks for the result. To enter an at-bat result, the user enters the number of bases earned by the batter. If the batter was out, the user enters 0. Otherwise, the user enters 1 for a single, 2 for a double, 3 for a triple, or 4 for a home run. After all the at-bat results are entered, the application displays the batting average and slugging percent.

Specifications

The batting average is the total number of at bats for which the player earned at least one base divided by the number of at bats. The slugging percentage is the total number of bases earned divided by the number of at bats. Use an array to store the at-bat results for a player. Validate the input so the user can enter only positive integers. For the at-bat results, the user's entry must be 0, 1, 2, 3, or 4. Validate the user's response to the question 'Another batter' so the user can enter only Y, y, N, or n. If the user enters Y or y, calculate the statistics for another batter. Otherwise, end the program. Format the batting average and slugging percent to show three decimal digits.

Enhancements

At the start of the program, prompt the user for the number of batters to enter. Then, save the statistics for all of the batters in a two-dimensional array. The program won't have to ask the user whether to enter data for another batter, since it will know how many batters are to be entered. After all batters have been entered, print a one-line summary for each batter:

Batter 1 average: 0.357 slugging percent: 0.650

Batter 2 average: 0.255 slugging percent: 0.550

Instead of storing an array of integers, create a class named AtBat and store instances of this class in the array. This class should define an enumeration named Result with members OUT, SINGLE, DOUBLE, TRIPLE, and HOMERUN. The class should have a constructor that accepts a Result parameter and a method named basesEarned that returns an int representing the number of bases earned for the at bat.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 12:00
An npn transistor is correctly biased and turned on if the a. base is negative. b. collector is negative. c. collector is positive with respect to the emitter and negative with respect to the base. d. collector is the most positive lead followed by the base.
Answers: 1
question
Computers and Technology, 24.06.2019 17:50
Which of the following best describe how the depth-limited search works. a normal depth-first search is performed but the number of ply/depths is limited. a normal breadth-first search is performed but the number of ply/depths is limited. a normal breadth-first search is performed but values above a specific value will be ignored. a normal depth-first search is performed but values above a specific value will be ignored.
Answers: 1
question
Computers and Technology, 24.06.2019 18:00
Explain the circumstances for which the interquartile range is the preferred measure of dispersion. what is an advantage that the standard deviation has over the interquartile range? choose the correct answer below. a. the interquartile range is preferred when the distribution is symmetric. an advantage of the standard deviation is that it increases as the dispersion of the data increases. b. the interquartile range is preferred when the data are not skewed or no have outliers. an advantage of the standard deviation is that it uses all the observations in its computation. c. the interquartile range is preferred when the distribution is symmetric. an advantage of the standard deviation is that it is resistant to extreme values. d. the interquartile range is preferred when the data are bell shaped. an advantage of the standard deviation is that it is resistant to extreme values. e. the interquartile range is preferred when the data are skewed or have outliers. an advantage of the standard deviation is that it uses all the observations in its computation. f. the interquartile range is preferred when the data are bell shaped. an advantage of the standard deviation is that it increases as the dispersion of the data increases.
Answers: 2
question
Computers and Technology, 25.06.2019 08:00
Is skill in using productivity software, such as word processors, spreadsheets, database management systems, and presentation software.computer literacyinformation literacybusiness literacynetwork literacy
Answers: 1
You know the right answer?
Calculate a player's batting statistics. Console

Welcome to the Batting Average Calcula...
Questions
question
Chemistry, 17.11.2020 18:30
question
Social Studies, 17.11.2020 18:30
question
Engineering, 17.11.2020 18:30
question
Mathematics, 17.11.2020 18:30
question
Mathematics, 17.11.2020 18:30