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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 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
Transcribed Image Text:* 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
* 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
Transcribed Image Text:* 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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Lock objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education