Microsoft Visual C# 7th edition. In Chapter 7, you modified the GreenvilleRevenue program to include a number of methods. Now, using your code from Chapter 7 Case Study 1, modify your program so every data entry statement uses a TryParse() method to ensure that each piece of data is the correct type. Any invalid user entries should generate an appropriate message that contains the word Invalid, and the user should be required to reenter the data. Cengage requirement for the shaded part is attached and I don't understand it. I need help with the highlighted part (getContestantData() method) please. Thanks
Microsoft Visual C# 7th edition. In Chapter 7, you modified the GreenvilleRevenue program to include a number of methods.
Now, using your code from Chapter 7 Case Study 1, modify your program so every data entry statement uses a TryParse() method to ensure that each piece of data is the correct type.
Any invalid user entries should generate an appropriate message that contains the word Invalid, and the user should be required to reenter the data.
Cengage requirement for the shaded part is attached and I don't understand it. I need help with the highlighted part (getContestantData() method) please. Thanks
using System;
using static System.Console;
using System.Globalization;
class GreenvilleRevenue
{
static void Main()
{
int numLastYear;
int numThisYear;
double revenue;
int fee = 25;
const int MAX_CONTESTANTS = 30;
string[] names = new string[MAX_CONTESTANTS];
char[] talents = new char[MAX_CONTESTANTS];
char[] talentCodes = { 'S', 'D', 'M', 'O' };
string[] talentCodesStrings = { "Singing", "Dancing", "Musical instrument", "Other" };
int[] counts = { 0, 0, 0, 0 }; ;
numLastYear = getContestantNumber("last", 0, 30);
numThisYear = getContestantNumber("this", 0, 30);
WriteLine("Last year's competition had {0} contestants, and this year's has {1} contestants", numLastYear, numThisYear);
revenue = (numThisYear * fee);
WriteLine("Revenue expected this year is {0}", revenue.ToString("C", CultureInfo.GetCultureInfo("en-US")));
DisplayRelationship(numThisYear, numLastYear);
getContestantData(numThisYear, names, talents, talentCodes, talentCodesStrings, counts);
getLists(numThisYear, talentCodes, talentCodesStrings, names, talents, counts);
}
public static int getContestantNumber(string when, int min, int max)
{
int contestants;
string contestantString;
WriteLine("Enter number of contestants {0} year >> ", when);
contestantString = ReadLine();
while(! int.TryParse(contestantString, out contestants))
{
WriteLine("Invalid");
WriteLine("Reenter the valid constestants number");
contestantString = ReadLine();
}
return contestants;
}
public static void DisplayRelationship( int numThisYear2, int numLastYear2)
{ if (numThisYear2 > 2 * numLastYear2)
WriteLine("The competition is more than twice as big this year!");
else
if (numThisYear2 > numLastYear2)
WriteLine("The competition is bigger than ever!");
else
if (numThisYear2 < numLastYear2)
WriteLine("A tighter race this year! Come out and cast your vote!"); }
public static void getContestantData(int numThisYear, string[] names, char[] talents, char[] talentCodes, string[] talentCodesStrings, int[] counts)
{ int x = 0;
bool isValid;
string talentString;
while (x < numThisYear)
{ Write("Enter contestant name >> ");
names[x] = Console.ReadLine();
WriteLine("Talent codes are:");
for (int y = 0; y < talentCodes.Length; ++y)
WriteLine(" {0} {1}", talentCodes[y], talentCodesStrings[y]);
Write(" Enter talent code >> ");
talentString = ReadLine();
while(! char.TryParse(talentString, out talents[x]))
{ WriteLine(" Invalid format - entry must be a single character");
WriteLine("That is not a valid code");
Write(" Enter talent code >> ");
talentString = ReadLine();}
talents[x] = GetChar();
isValid = false;
while (!isValid)
{for (int z = 0; z < talentCodes.Length; ++z)
{
if (talents[x] == talentCodes[z])
{isValid = true;
++counts[z];
}
}
if (!isValid)
{WriteLine("{0} is not a valid code", talents[x]);
Write(" Enter talent code >> ");
talents[x] = GetChar();
}
}
++x;
}
}
public static void getLists(int numThisYear, char[] talentCodes, string[] talentCodesStrings, string[] names, char[] talents, int[] counts)
{int x;
char QUIT = 'Z';
char option;
bool isValid;
int pos = 0;
bool found;
WriteLine("\nThe types of talent are:");
for (x = 0; x < counts.Length; ++x)
WriteLine("{0, -20} {1, 5}", talentCodesStrings[x], counts[x]);
WriteLine("\nEnter a talent type or {0} to quit >> ", QUIT);
option = GetChar();
while (option != QUIT)
{ isValid = false;
for (int z = 0; z < talentCodes.Length; ++z)
{if (option == talentCodes[z])
{ isValid = true;
pos = z;
}
}
if (!isValid)
WriteLine("{0} is not a valid code", option);
else
{ WriteLine("\nContestants with talent {0} are:", talentCodesStrings[pos]);
found = false;
for (x = 0; x < numThisYear; ++x)
{ if (talents[x] == option)
{WriteLine(names[x]);
found = true;}
}
if (!found)
Console.WriteLine("No contestants had talent {0}", talentCodesStrings[pos]);
}
WriteLine("\nEnter a talent type or {0} to quit >> ", QUIT);
option = GetChar();
}
}
private static char GetChar()
{char validChar = '0';
bool isValidChar = false;
var charInput = string.Empty;
while (!isValidChar)
{ charInput = Console.ReadLine();
isValidChar = Char.TryParse(charInput, out validChar);
if (!isValidChar)
{
WriteLine("Invalid character - Please try again by entering one character!");
/* WriteLine("Invalid format - entry must be a single character");
}
else
WriteLine("That is not a valid code");*/
}
}
return validChar;-
}
}
![* MindTap - Cengage Learning
+
A ng.cengage.com/static/nb/ui/evo/index.html?deploymentld=599280232553470917272565870&elSBN=9780357429235&id=1020785584&snapshotld=2132259&
CENGAGE MINDTAP
Q Search this course
Case Problem 8-1
Tasks
>- Terminal
+
Enter number of contestants last year >>
using (StringWriter sw = new Stringwriter())
{
A-Z
Console. SetIn(inputs);
Console.Setout(sw);
</>
string[] names = new string[30];
char[] talents = new char[30];
char[] talentCodes = {'S', 'D', 'M', 'o'};
string[] talentCodesStrings = {"Singing", "Dancing", "Musical instrument", "Oth
int[] counts = {0, 0, 0, 0};
GreenvilleRevenue.getContestantData(2, names, talents, talentCodes, talentCodes
string expected = "invalid";
Assert.AreEqual(2, counts[1]);
StringAssert.Contains(expected, sw.ToString().Trim().ToLower());
Assert.AreEqual("Joe", names[0]);
Assert. AreEqual("Ann", names[1]);
Assert.AreEqual('D', talents[0]);
Assert. AreEqual('D', talents[1]);
}
Run Checks
Submit 66%
2:17 AM
P Type here to search
4) ENG
3/25/2021
* D 2 O E](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff0d9f87b-969b-43db-b857-7c9fbe41e51a%2Fe8b620de-ce3c-44fd-a423-f426d9208870%2Frcro2uf_processed.png&w=3840&q=75)
![* MindTap - Cengage Learning
+
A ng.cengage.com/static/nb/ui/evo/index.html?deploymentld=599280232553470917272565870&elSBN=9780357429235&id=1020785584&snapshotld=2132259&
CENGAGE MINDTAP
Q Search this course
Case Problem 8-1
Tasks
>- Terminal
+
Enter number of contestants last year >>
Test Output ©
A-Z
</>
Test Contents e
[TestFixture]
public class getContestantDataMethodTest
{
[Test]
public void getContestantDataTest()
{
string consoleInput = "Joe\nD\nAnn\n99\nD";
using (var inputs = new StringReader (consoleInput))
{
using (StringWriter sw = new Stringwriter())
{
Console. SetIn(inputs);
Console.SetOut(sw);
strina(1 names = new strina(3A -
Run Checks
Submit 66%
2:14 AM
P Type here to search
4) ENG
3/25/2021
* E 2 O E](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff0d9f87b-969b-43db-b857-7c9fbe41e51a%2Fe8b620de-ce3c-44fd-a423-f426d9208870%2Fcdd82dh_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)