using System.Collections.Generic; using System.Globalization; class GreenvilleRevenue { static void Main() { int contestantsLastYear; int contestantsThisYear; string contestantName;

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
icon
Concept explainers
Question

THIS IS FOR C#. I need help fixing the code. 

Here is my code:

using System;
using System.Collections.Generic;
using System.Globalization;

class GreenvilleRevenue
{
static void Main()
{
int contestantsLastYear;
int contestantsThisYear;
string contestantName;
string talentCode;
List<string> talentCodes = new List<string>();
List<string> contestantNames = new List<string>();

Console.Write("Enter number of contestants last year >> ");
while (!int.TryParse(Console.ReadLine(), out contestantsLastYear))
{
Console.WriteLine("Invalid format - entry must be a number");
Console.Write("Enter number of contestants last year >> ");
}

Console.Write("Enter number of contestants this year >> ");
while (!int.TryParse(Console.ReadLine(), out contestantsThisYear))
{
Console.WriteLine("Invalid format - entry must be a number");
Console.Write("Enter number of contestants this year >> ");
}

Console.WriteLine("Last year's competition had {0} contestants, and this year's has {1} contestants", contestantsLastYear, contestantsThisYear);
Console.WriteLine("Revenue expected this year is {0:C}", contestantsThisYear * 25);
if (contestantsThisYear > contestantsLastYear)
{
Console.WriteLine("The competition is bigger than ever!");
}
else
{
Console.WriteLine("The competition is the same as last year");
}

while (true)
{
Console.Write("Enter contestant name >> ");
contestantName = Console.ReadLine();
if (contestantName == "")
{
break;
}
Console.WriteLine("Talent codes are:");
Console.WriteLine(" S Singing");
Console.WriteLine(" D Dancing");
Console.WriteLine(" M Musical instrument");
Console.WriteLine(" O Other");
Console.Write(" Enter talent code >> ");
talentCode = Console.ReadLine();
while (talentCode != "S" && talentCode != "D" && talentCode != "M" && talentCode != "O")
{
Console.WriteLine("Invalid format - entry must be a single character");
Console.WriteLine("That is not a valid code");
Console.Write(" Enter talent code >> ");
talentCode = Console.ReadLine();
}
talentCodes.Add(talentCode);
contestantNames.Add(contestantName);
}

Console.WriteLine("\nThe types of talent are:");
Console.WriteLine("Singing {0}", getLists(talentCodes, "S"));
Console.WriteLine("Dancing {0}", getLists(talentCodes, "D"));
Console.WriteLine("Musical instrument {0}", getLists(talentCodes, "M"));
Console.WriteLine("Other {0}", getLists(talentCodes, "O"));

string talentType;
Console.Write("\nEnter a talent type or Z to quit >> ");
talentType = Console.ReadLine();
while (talentType != "Z")
{
Console.WriteLine();
getContestantData(talentType, talentCodes, contestantNames);
Console.Write("\nEnter a talent type or Z to quit >> ");
talentType = Console.ReadLine();
}
}

static int getLists(List<string> talentCodes, string talentCode)
{
int count = 0;
foreach (string code in talentCodes)
{
if (code == talentCode)
{
count++;
}
}
return count;
}

static void getContestantData(string talentType, List<string> talentCodes, List<string> contestantNames)
{
Console.WriteLine("Contestants with talent type {0} are:", talentType);
for (int i = 0; i < talentCodes.Count; i++)
{
if (talentCodes[i] == talentType)
{
Console.WriteLine(" {0}", contestantNames[i]);
}
}
}
}

 

 

 

 

 

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.

 

 

 

I have submitted this multiple times, so please help fix this. 

Enter number of contestants
last year >> 1
Enter number of contestants this year >> 2
Last year's competition had 1 contestants, and this y
Revenue expected this year is $50.00
The competition is bigger than ever!
Enter contestant name >> Matt
Talent codes are:
S Singing
D
Dancing
M Musical instrument
0
Other
Enter talent code >> Sarah.
Invalid format - entry must be a single character
That is not a valid code
Enter talent code >> R
That is not a valid code
Enter talent code >> J
That is not a valid code
Enter talent code >> S
Enter contestant name >> Sarah
Talent codes are:
S
Singing
D
Dancing
M
Musical instrument
0
Other
Enter talent code >> D
The types of talent are:
Singing
Dancing
Musical instrument
Other
1
HH
1
0
Enter a talent type or Z to quit >> Z
Transcribed Image Text:Enter number of contestants last year >> 1 Enter number of contestants this year >> 2 Last year's competition had 1 contestants, and this y Revenue expected this year is $50.00 The competition is bigger than ever! Enter contestant name >> Matt Talent codes are: S Singing D Dancing M Musical instrument 0 Other Enter talent code >> Sarah. Invalid format - entry must be a single character That is not a valid code Enter talent code >> R That is not a valid code Enter talent code >> J That is not a valid code Enter talent code >> S Enter contestant name >> Sarah Talent codes are: S Singing D Dancing M Musical instrument 0 Other Enter talent code >> D The types of talent are: Singing Dancing Musical instrument Other 1 HH 1 0 Enter a talent type or Z to quit >> Z
Unit Test Incomplete
Method getContestant Number uses TryParse() to detect
invalid entries
Unit Test Incomplete
Method getContestant Data uses TryParse() to detect
invalid input
Unit Test Incomplete
Method getLists uses TryParse() to detect invalid input
Transcribed Image Text:Unit Test Incomplete Method getContestant Number uses TryParse() to detect invalid entries Unit Test Incomplete Method getContestant Data uses TryParse() to detect invalid input Unit Test Incomplete Method getLists uses TryParse() to detect invalid input
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Types of Linked List
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
  • SEE MORE 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