Computers and Technology

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.

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:00, kadariusmerchan
Determine which of the four levels of measurement (nominal, ordinal, interval, ratio) is most appropriate for the data below. internet speed levels of "fast comma " "medium comma " and "slow" choose the correct answer below. a. the ordinal level of measurement is most appropriate because the data can be ordered comma but differences left parenthesis obtained by subtraction right parenthesis cannot be found or are meaningless. nothing nothing nothing nothing nothing b. the interval level of measurement is most appropriate because the data can be ordered comma differences left parenthesis obtained by subtraction right parenthesis can be found and are meaningful comma and there is no natural starting point. c. the nominal level of measurement is most appropriate because the data cannot be ordered. nothing d. the ratio level of measurement is most appropriate because the data can be ordered comma differences left parenthesis obtained by subtraction right parenthesis can be found and are meaningful comma and there is a natural starting point.
Answers: 2
image
Computers and Technology, 22.06.2019 06:00, wbrandi118
What role do chromosomes play in inheritance?
Answers: 1
image
Computers and Technology, 22.06.2019 12:40, Rententen3845
How do i get the most points, without any effort?
Answers: 2
image
Computers and Technology, 23.06.2019 07:30, barkonatree
What is the penalty for violating section 1201 of title 17 chapter 21 of the us code
Answers: 1
Do you know the correct answer?
Calculate a player's batting statistics. Console

Welcome to the Batting Average Calcula...

Questions in other subjects:

Konu
English, 22.12.2020 19:00
Konu
Biology, 22.12.2020 19:00
Konu
Mathematics, 22.12.2020 19:00