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, 21.06.2019 22:30
Ted wants to go out to a neighborhood park and shoot pictures of dew drops on grass. he wants to get a low-level angle of the dew drops. which support equipment should ted use? a. mini tripod b. pistol grip c. monopod d. body mount
Answers: 2
question
Computers and Technology, 23.06.2019 04:31
Type the correct answer in the box. spell all words correctly. the managing director of a company sends a christmas greeting to all his employees through the company email. which type of network does he use? he uses an
Answers: 1
question
Computers and Technology, 23.06.2019 18:30
Where can page numbers appear? check all that apply. in the header inside tables in the footer at the bottom of columns at the top of columns
Answers: 1
question
Computers and Technology, 23.06.2019 23:30
What are "open-loop" and "closed-loop" systems
Answers: 1
You know the right answer?
Calculate a player's batting statistics. Console

Welcome to the Batting Average Calcula...
Questions
question
Mathematics, 27.03.2020 23:54
question
Mathematics, 27.03.2020 23:55
Questions on the website: 13722363