Question
In previous chapters, you have created programs for the Greenville Idol competition. Now create a Contestant class with the following characteristics: - The Contestant class
In previous chapters, you have created programs for the Greenville Idol competition.
Now create a Contestant class with the following characteristics:
- The Contestant class contains public static arrays that hold talent codes and
descriptions. Recall that the talent categories are Singing, Dancing, Musical
instrument, and Other.
- The class contains an auto-implemented property that holds a contestants name.
- The class contains fields for a talent code and description. The set accessor for
the code assigns a code only if it is valid. Otherwise, it assigns I for Invalid. The
talent description is a read-only property that is assigned a value when the code
is set.
Modify the GreenvilleRevenue program so that it uses the Contestant class and
performs the following tasks:
- The program prompts the user for the number of contestants in this years
competition; the number must be between 0 and 30. The program continues to
prompt the user until a valid value is entered.
- The expected revenue is calculated and displayed. The revenue is $25 per contestant.
- The program prompts the user for names and talent codes for each contestant
entered. Along with the prompt for a talent code, display a list of the valid categories.
- After data entry is complete, the program displays the valid talent categories and
then continuously prompts the user for talent codes and displays the names of all
contestants in the category. Appropriate messages are displayed if the entered code is
not a character or a valid code.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chapter8
{
class Chapter8
{
static void Main(string[] args)
{
int lastYearContestants;
int thisYearContestants;
ArrayList talentCodes = new ArrayList { "S", "D", "M", "O" };
int[] talentCounts = { 0, 0, 0, 0 };
const string QUIT = "Q";
Console.WriteLine("Please enter the number of contestants entered in last year's competition: ");
lastYearContestants = GetContestants();
Console.WriteLine("Please enter the number of contestants entered in this year's competition: ");
thisYearContestants = GetContestants();
String[] names = new String[thisYearContestants];
String[] talents = new String[thisYearContestants];
//call DisplayContestantMessage method
DisplayContestantMessage(thisYearContestants, lastYearContestants);
//call FillArrays method
FillArrays(thisYearContestants, names, talents, talentCounts, talentCodes);
Console.WriteLine(" **************************************************************** ");
for (int i = 0; i < talentCodes.Capacity; i++)
{
Console.Write("Code " + talentCodes[i] + " has count " + talentCounts[talentCodes.IndexOf(talentCodes[i])] + " ");
}
Console.WriteLine(" **************************************************************** ");
//call PromptTalentCodes method
PromptTalentCodes(QUIT, talentCodes, names, talents);
} // end main method
static void DisplayContestantMessage(int thisYearContestants, int lastYearContestants)
{
if ((lastYearContestants >= 0) && (lastYearContestants <= 30) && (thisYearContestants >= 0) && (thisYearContestants <= 30)) ;
Console.WriteLine("The revenue expected for this year's competition : $" + thisYearContestants * 25 + ' ');
if (thisYearContestants > lastYearContestants * 2)
Console.WriteLine("The competition is more than twice as big this year! ");
else
if (thisYearContestants > lastYearContestants && thisYearContestants <= (lastYearContestants * 2))
Console.WriteLine("The competition is bigger than ever! ");
else
if (thisYearContestants < lastYearContestants)
Console.WriteLine("A tighter race this year! Come out and cast your vote! ");
} // end DisplayContestantMessage
static void PromptTalentCodes(string QUIT, ArrayList talentCodes, string[] names, string[] talents)
{
Console.WriteLine("To see the contestants by talent, please search a valid talent code or " + QUIT + " to end:");
string input = Console.ReadLine();
while (input != QUIT)
{
while (!talentCodes.Contains(input) && input != QUIT)
{
Console.WriteLine("Invalid code. Please search a valid talent code or " + QUIT + " to end:");
input = Console.ReadLine();
}
if (input == QUIT) break;
//Console.WriteLine("Contestants signed up for " + talents[talentCodes.IndexOf(input)] + ": ");
for (int i = 0; i < names.Length; i++)
{
if (talents[i] == input)
Console.WriteLine(names[i]);
}
Console.WriteLine(" Search for another talent code?");
Console.WriteLine("To see the contestants by talent, please search a valid talent code or " + QUIT + " to end:");
input = Console.ReadLine();
} // end while loop
}//end PromptTalentCodes
static void FillArrays(int thisYearContestants, string[] names, string[] talents, int[] talentCounts, ArrayList talentCodes)
{
int x;
string input;
for (x = 0; x < thisYearContestants; x++)
{
Console.WriteLine("Enter Contestant Name: ");
names[x] = Console.ReadLine();
Console.WriteLine("Talent codes are: S Singing D Dancing M Musical instrument O Other Enter talent code: ");
input = Console.ReadLine();
while (!talentCodes.Contains(input))
{
Console.WriteLine("Please enter a valid talent code.");
Console.WriteLine("Talent codes are: S Singing D Dancing M Musical instrument O Other Enter talent code: ");
input = Console.ReadLine();
}
talents[x] = input;
talentCounts[talentCodes.IndexOf(input)]++;
}
} // end FillArrays method
static int GetContestants()
{
int contestants;
string input = Console.ReadLine();
while (!Int32.TryParse(input, out contestants) || (contestants < 0 || contestants > 30))
{
Console.WriteLine("Error. Please enter a value between 0 and 30.");
input = Console.ReadLine();
}
return contestants;
} //end GetContestants method
} // end class
} // end namespace
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started