A Little League baseball team has 12 players who have jersey numbers 0 (yes, 0)
ID: 670949 • Letter: A
Question
A Little League baseball team has 12 players who have jersey numbers 0 (yes, 0) through 11. The coach wants a program into which he can type a player's jersey number and the number of bases the player got in a single turn at bat (a number between 0 and 4) for any number of "at bats" for each player (note: your sample data does not have to include "at bats" for all 11 players...just use 3 or 4 players and have each player have a few "at bats" each.
Write a C# Console app (name it TeeBall) that allows the coach to continually enter the values until 99 (sentinel value) is entered. Store the statistics in a two-dimensional array. At the end of a data-entry session (coach enters 99 to end), display each player's jersey number and the number of 0-base, 1-base, 2-base, 3-base, and 4-base (a home run) turns the player had. Display a separate count of the number of data-entry errors the coach makes (a player number greater than 11 or a number of bases greater than 4).
Hint: Create a two-dimensional array that is 12 x 5 (12 players and 5 potential "bases"). Each data entry for an "at bat" would include a player's jersey number and the base the player got to when he/she hit the ball (0 = made an out, 1 = first base, 2 = second base, 3 = third base, 4 = home run). You should add +1 to the totals that are being held in the array for each player's turn at bat. Need further clarification? Email me with your question(s)! The source code solution for the Console version of this problem is only about 3 dozen lines of C# code!!! :-) Your Console App could look something like this:
5 base, 4 home run, 9-done> Enter the base (0-out, 1-1st base Enter the base t, 1-1st base, 2-2nd base, 3-3rd base, 4-home run, 9-done>> Enter the base (0- ut, 1-1st bas e , 2=2nd base, 3-3rd base. 4-home run, 9-d ne>> Enter the base (0-out, 1-1st base, 2=2nd base, 3-3rd base, 4shone run, 9-done >> Enter the base (0-out, 1-1st base, 2=2nd base, 3-3rd base, 4-home run, 9-done >> Enter the base (0-out, 1-1st bas e " 2=2nd base, 3=3rd base' 4-home run, 9-done >> Enter the base (0-out, 1-1st bas e " 2=2nd base, 3=3rd base' 4-home run, 9-done Enter the base (0-out, 1-1st bas e . 2=2nd base, 3=3rd base' 4-home run, 9-done Enter the base (0-out" 1-1st bas e " 2=2nd base, 3=3rd base' 4-home run, 9-done Enter the player number or 99 to quit 6 5 Enter the base (0-out. 1-1st base, 2:2nd base. 3:3rd bas e . 4zhome run, 9-done>> Enter the base (0-out. 1-1st bas e . 2:2nd base, 3=3rd base' 4-home run, 9-done Enter the base (0-out. 1-1st bas e . 2=2nd base, 3-3rd base, 4-home run. 9-done Enter the base (0out. 1-1st base, 2-2nd base, 3-3rd base, 4-home run, 9-done Enter the bas e (0-out, 1-1st bas e 2-2nd bas e . 3:3rd bas e ' 4-home run, 9-done >> Enter the base (Oout. 1-1st base, 2-2nd base, 3-3rd base, 4home run, 9-done> Enter the player number or 99 to qit 99 Layer Summary ases 6 ayer ro One Two Three Fo 9 8Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TeeBall
{
class Program
{
static void Main(string[] args)
{
int[,] scoreArr = new int[12,5];
int playerError = 0;
int baseError = 0;
string input = null;
int playerNo = -1;
int baseOpt = -1;
string msg = "Enter the player number ( 0 to 11) or 99 to Quit";
//inialize scoreArr to = 0;
for (int i = 0; i < 12; i++)
{
for (int j = 0; j < 5; j++)
{
scoreArr[i, j] = 0;
}
}
while (playerNo != 99 && baseOpt != 99)
{
Console.WriteLine(msg);
input = Console.ReadLine();
playerNo = Convert.ToInt32(input);
if (playerNo >= 0 && playerNo <= 11)
{
//Now read base
Console.WriteLine(" Enter the base (0 = made an out, 1 = first base, 2 = second base, 3 = third base, 4 = home run) ");
while (true)
{
input = Console.ReadLine();
baseOpt = Convert.ToInt32(input);
if (baseOpt >= 0 && baseOpt <= 4)
{
scoreArr[playerNo, baseOpt] = scoreArr[playerNo, baseOpt] + 1;
break;
}
else
{
Console.WriteLine(" Enter valid base option : ( 0 to 4) ");
baseError++;
}
}
}
else
{
msg = (" Enter valid player number : ( 0 to 11) ");
playerError++;
}
}
//display the results
Console.WriteLine("Player Summary: ");
Console.WriteLine("Player Bases: ");
Console.WriteLine(" Zero One Two Three Four");
for (int i = 0; i < 12; i++)
{
Console.Write(i);
for (int j = 0; j < 5; j++)
{
Console.Write(" "+j+" ");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.