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, 22.06.2019 15:50
The file sales data.xlsx contains monthly sales amounts for 40 sales regions. write a sub that uses a for loop to color the interior of every other row (rows 3, 5, etc.) gray. color only the data area, columns a to m. (check the file colors in excel.xlsm to find a nice color of gray.)
Answers: 2
question
Computers and Technology, 23.06.2019 00:20
Ihave been given the number of guns per 100, and the total firearm-related deaths per 100,000. i have to find the actual number of guns per country and actual number of gun-related deaths. if somebody could show me how to do 1 question, i can finish the rest, i am just confused. tia
Answers: 3
question
Computers and Technology, 23.06.2019 04:31
Acloud service provider uses the internet to deliver a computing environment for developing, running, and managing software applications. which cloud service model does the provider offer? a. iaas b. caas c. maas d. paas e. saas
Answers: 1
question
Computers and Technology, 23.06.2019 13:00
In excel - calculate the actual increase/decrease from first quarter to the second quarter then subtract subtract first quarter value from second quarter total then divide result by first quarter value
Answers: 1
You know the right answer?
Calculate a player's batting statistics. Console

Welcome to the Batting Average Calcula...
Questions
question
Mathematics, 02.09.2020 04:01
question
Mathematics, 02.09.2020 04:01
question
Mathematics, 02.09.2020 04:01
Questions on the website: 13722367